nodejs连接Mysql数据库报错
Client does not support authentication protocol requested by server; consider upgrading MySQL client
一、背景描述
最近在写nodejs的项目,于是用nodejs连接Mysql数据库
二、代码
const mysql = require('mysql');
// 创建连接
const conn = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'Mysql123',
port: '3306',
database: 'myblognode'
});
// 开始连接
conn.connect();
const sql = `insert into blogs(title,content,createtime,author) values('标题6','内容6',1625493590564,'yolanda')`;
conn.query(sql, (err, res) => {
if(err) {
console.error(err)
return
}
console.log(res)
})
// 关闭连接
conn.end();
三、错误描述
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
四、解决办法
1、分析一下
参考了stackoverflow的这个回答
https://stackoverflow/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server
原因是因为mysql8之前版本加密规则是mysql_native_password,之后是caching_sha2_password
当然看得懂错误的意思是要升级啦,那现在就是不想升级呀!我mysql和MysqlWorkBench的版本都是8.0.20,这是因为我的mac版本是10.15,我用不了高版本的mysql,要不然就要升级mac系统,但是我又不想升级我的mac版本,好了,禁止套娃!
现在要改成mysql_native_password
2、先找到我的mysql装哪去了?
打开系统偏好设置
切换一下tab页到Configuration
3、打开终端输入命令
/usr/local/mysql/bin/mysql -u root -p
然后就出来mysql> 这个东东啦
4、依次输入命令
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Mysql123';
mysql> FLUSH PRIVILEGES;
mysql> quit
五、成功啦~
秃头少女在线请求,给我点个赞吧~
更多推荐
nodejs连Mysql报错Client does not support authentication protocol requested by serve
发布评论