连接 Mysql 8.0.27 出现1251- Client does not support authentication protocol 解决方案

目前在Ubuntu的linux上安装了mysql版本是8.0.27,发现Navicat for MySQL 和 python 中的 Django 调用 mysql 也链接不上,提示如下信息:

mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

1251 - Client does not support authentication protocol requested by server; consider upgrading MySQl client

mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password, 

解决问题方法有两种:

方法1.升级navicat驱动;

方法2.把mysql用户登录密码还原成mysql_native_password. 

这里采用方法2解决,具体操作步骤如下:

1.打开linux命令行终端,进入MySQL的bin目录,然后输入mysql -u root -p,输入密码

root@iZ2ze9bmb26dc11q1lwx6lZ:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2021, 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>

2.然后在mysql中输入

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; #更新一下用户的密码,123456为自定义密码 

FLUSH PRIVILEGES; #刷新权限

3.使用Navicat for MySQL,再次测试连接,你会惊喜地发现连接成功了