# 查看密码 [root@izuf61151k3ad2dso6mo9oz mysql]# grep "password" /var/log/mysqld.log 2021-04-21T14:41:47.850679Z 1 [Note] A temporary password is generated for root@localhost: Tt;vkIhrd71? 2021-04-21T14:44:16.590080Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES) 2021-04-21T14:44:30.478638Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES) # 进入 mysql 修改 root 用户的密码 update mysql.user set authentication_string=password('shijinying123!@#') where user='root'; # 修改之后刷新 flush privileges; # 输入命令会报错误,或者先执行刷新语句,在执行修改密码语句 mysql> flush privileges; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. # 出现这种情况一次执行一下命令 SET PASSWORD = PASSWORD('Shijinying123!@#'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; flush privileges; # 这里需要说明一下:密码必须包含数字,字母包含大小写,标点符号。不然是不能通过的。 # 完成之后就可以使用新密码登录了 mysql -u root -p Shijinying123!@# # 修改 root 用户远程 连接 update user set host = '%'where user ='root'; # 直接修改 root 用户 # 修改完刷新数据库 flush privileges; # 新增一条 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Shijinying123!@#' WITH GRANT OPTION;