Mysql 8.0 遇到用遇到的几个问题及解决办法

2059 - Authentication plugin ‘caching_sha2_password’

Mysql 8.0 遇到用遇到的几个问题及解决办法_第1张图片

问题原因,Mysql8.0开始加密用的是caching_sha2_password,之前用的是mysql_native_password

解决办法,更改加密规则

mysql -uroot -ppassword #登录

use mysql; #选择数据库
# password换成你的密码,远程连接请将'localhost'换成'%'
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER; #更改加密方式
# password换成你的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码'; #更新用户密码

FLUSH PRIVILEGES; #刷新权限

客户端远程连接时

Mysql 8.0 遇到用遇到的几个问题及解决办法_第2张图片


mysql>use mysql;
# 创建远程连接%
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.02 sec)
# 修改远程连接的加密方式为mysql_native_password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码!';
Query OK, 0 rows affected (0.01 sec)
# 刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
# 查看用户,下面这个就是为远程创建的远程
mysql> select Host,User,plugin from mysql.user;
 %             | root             | mysql_native_password 

Linux 登录时,ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO/YES)

问题原因,本地密码不小心更新了或者忘记了
解决办法,停掉数据库,修改my.cnf配置文件

# 停掉MySQL服务
service mysqld stop
# 查看状态
service mysqld status
#查找my.cnf
whereis my.cnf
# 编辑文件
vim my.cnf
## !添加跳过密码验证
skip-grant-tables
# 重启MySQL服务
service mysqld restart
## !输入进入mysql命令后,直接回车进入
mysql -u root -p
# 更新密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
## 刷新权限,否则会报错1290,解决办法见下面
flush privileges;
## !记得回去把跳过密码验证删了
#skip-grant-tables
# 重启MySQL服务
 service mysqld restart
#用新密码登录
mysql -u root -p

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

问题原因,增加了跳过密码,没有刷新权限
解决办法,MySQL里执行

flush privileges;

update user set password=password(“root”) where user=“root”; 报错

mysql> update user set password=password("你的密码") where user="root";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("你的密码") where user="root"' at line 1

把password改为authentication_string后,发现还是提示错误
mysql> update user set authentication_string=password("root") where user="root";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '("123456") where user="root"' at line 1

问题原因,语句格式错误,但是网上大多数都是这几个更新语句
后面查看*https://blog.csdn.net/weixin_43645330/article/details/83869490*找到了原因

# 更换语句
mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
Query OK, 0 rows affected (0.01 sec)

你可能感兴趣的:(Linux,linux,mysql)