主要是由于mysql8以前的加密规则与mysql8以后的存在差异。

mysql连数据库的时候报错:

1251 client does not support authentication protocol requested by server;consider upgrading Mysql client

ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
 

第一步:首先登录mysql:

C:\WINDOWS\system32>mysql -u root -p
Enter password: ******

出现如下界面表示登陆成功:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

第二步:在mysql>后面输入use mysql;(包括分号)

第三步:在mysql>后面输入select user,host from user;

接下来会出现如下界面:

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

通过这个我们可以查看到root对应的是"%";

第四步:在mysql>后面输入: ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;(@后面的%一定不要忘记改;因为上面我们查到root对应是%)

当出现:Query OK, 0 rows affected (0.01 sec)这一步执行没有问题;

第五步:mysql>后面输入:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';(%不要忘记改,最后的密码输入自己设置的密码);出现Query OK, 0 rows affected (0.00 sec),代表成功;

第六步:mysql> 后面输入:FLUSH PRIVILEGES;

新建一个sqlyog数据库:测试连接:就可以连接成功了!

 

Logo

更多推荐