使用node 中的 mysql 包 连接 mysql 报错
Database connection failed: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
具体报错截图:
原因
最新的mysql模块并未完全支持MySQL 8
的“caching_sha2_password
”加密方式,而“caching_sha2_password
”在MySQL 8
中是默认的加密方式。因此,下面的方式命令是默认已经使用了“caching_sha2_password
”加密方式,该账号、密码无法在mysql
模块中使用。
解决方法:
修改加密方式
1、use mysql;
2、alter user 'root'@'localhost' identified with mysql_native_password by '你的数据库密码';
3、flush privileges;
注:如果采用的是命令行窗口,确认是否是以管理员的身份打开。