当在Node中使用mysql连接mysql8时,相关配置没错,但是报错如下:
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
原因:
mysql从8.04引入一个caching_sha2_password模块作为默认身份验证插件,数据库连接时验证身份的工作方式(handshake process)会与以往不同。
解决方案一:
删除旧连接器
npm uninstall mysql
使用新连接器
npm i mysql2
导入模块
const mysql = require('mysql2')
解决方案二
登录mysql,运行以下代码
先运行:
alter user 'root'@'localhost' identified with mysql_native_password by ‘你的密码’;
再运行:
flush privileges;