MAC/Windows Node.Js无法正常连接MySQL8.0报错 ER_NOT_SUPPORTED_AUTH_MODE

异常信息如下

 {
        "code": "ER_NOT_SUPPORTED_AUTH_MODE",
        "errno": 1251,
        "sqlMessage": "Client does not support authentication protocol requested by server; consider upgrading MySQL client",
        "sqlState": "08004",
        "fatal": true
}

博主使用工具版本如下

            Node.Js 版本 14.3.0

           MySQL版本 8.0.19

其实这个问题很简单,在我早期的博文里也有说明,这个问题形成的原因是MySQL8.0默认的密码验证方案是caching_sha2_password  而Node.Js默认密码验证方案是 mysql_native_password 所以即使你的密码是正确,但是你还是验证不了依旧会报错,那么如何解决呢?解决办法把下面的命令一条一条的复制到你的终端或命令提示符里去执行

# 1、登录MySQL,使用命令
  mysql -u root -p或mysql -u root -ppassword【ps:-ppassword后面的密码是你的root密码】

# 2、修改加密规则
  ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

# 3、更新用户密码 
 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

# 4、刷新权限
 FLUSH PRIVILEGES; 

# 5、重置密码
 alter user 'root'@'localhost' identified by '你的密码';

Ps:如果你的Navicat12 或SQLyog工具连接MySQL8出现异常2059-Authentication plugin 'caching_sha2_password' cannot be loaded请看这里点我查看解决方案

猜你喜欢

转载自blog.csdn.net/weixin_40845165/article/details/106369319#comments_27509583
今日推荐