今天在学习一个小 demo,用 node.js+mysql 时踩了些坑,记录一下。我用的是 mysql 8.0。
用 express 配置好数据库信息后,用 navicat 连接 mysql,报错:
Client does not support authentication protocol requested by server; consider upgrading MySQL client
原因:mysql模块暂时不支持MySQL8.0版本默认的加密方式(caching_sha2_password),连接会报错。
解决办法:
- 通过命令行进入解压的mysql根目录下
- 登陆数据库 mysql -uroot -p
- 输入root的密码 Enter password: ******
- 更改加密方式(原样拷贝到命令窗中) mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘password’ PASSWORD EXPIRE NEVER;
- 更改密码,该例子中 123456为新密码 mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
- 刷新 mysql> FLUSH PRIVILEGES;
完成上述操作后又报错:
Access denied for user ‘root’@‘localhost’(using password: NO)
检查:服务器已启动,端口无误。根