解决不能连接MySQL数据库问题

作者:陆金龙    发表时间:2018-08-20 11:20   

关键词:Client does not support authentication protocol requested by server  

1.mysql用户访问权限

    MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost只能本机访问;

    其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问。

   进入mysql数据库
   $mysql -u root -p
   >use mysql;
   >select host,user from user;

    发现所有记录的host字段的值都是localhost,将其改为%,重启mysql服务,再尝试远程连接。

    经以上步骤,重启后,如果还是不能远程连接,则执行第2步。

2.关闭防火墙

   开了防火墙,并配置了入站规则也并不能访问。

   尝试直接关闭防火墙,连接成功!!

3.报错:Client does not support authentication protocol requested by server

  原因:MySQL8 之前的版本中加密规则是mysql_native_password,而在MySQL8之后,加密规则是caching_sha2_password。

  方法:使用Navicat Premium 15替代Navicat for MySQL 11

4.1045 Access denied错误 

1045“Access denied for user ‘root’@‘localhost’ (using password: YES)”

1)修改密码:注意mysql5.7 的 user表的密码字段从 password 变成了 authentication_string

    5.7以前:update mysql.user set password=password('123456') where user='**';

                   执行flush privileges; 立即生效。

    5.7以后:update mysql.user set authentication_string=password('123456') where user='**';

                   执行flush privileges; 立即生效。

2)为新密码设置权限

      ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’;