使用node 连接 mysql 报错
at node:internal/main/run_main_module:17:47 { 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 }
通过网上查看解决方案,是因为mysql8.0默认的密码认证方案是'caching_sha2_password',而目前node默认的密码认证方案是'mysql_native_password',所以即使密码是对的,但是却无法认证成功。
用户名:root
密码:123456
解决方案
1、使用管理员运行命令提示符
2、进入到mysql安装目录的bin目录下默认安装路径大概是(C:\Program Files\MySQL\MySQL Server 8.0\bin)
3、在命令提示行中键入: mysql -u root -p
4、mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
此时得到提示Query OK, 0 rows affected (0.01 sec),这里是修改密码的认证方式
5、mysql> flush privileges;此时得到提示Query OK, 0 rows affected (0.01 sec),这里是重启权限
6、mysql> exit 退出mysql