小白尝试使用Javascript语言连接MySQL数据库,结果出现了如下错误:
[SELECT ERROR] - ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
查阅网上资料,看到如下解决办法,所以来记录一下。
解决方法:
- 最好MySQL数据库初始化是有密码的,比如我是 user:
root
,password:root
- 连接进入MySQL数据库
- 输入
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
- 再然后进入Node.js 连接数据库就不报错误了,就可以查询成功了。
- 原博客输入了两条命令,但我是刚刚初始化修改的密码,所以就只输入了第二个,好在解决了,如果不能解决就输入两个吧。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRENEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '修改自己的密码';
我用到的命令如下:
mysql -u root -p
Enter password: root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
参考博客地址: https://www.cnblogs.com/tourey-fatty/p/12522784.html