nodejs连Mysql报错Client does not support authentication protocol requested by server; consider upgradin

编程知识 更新时间:2023-05-02 05:24:54

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

本文发布于:2023-04-26 06:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/816bdc231b67b1d89d04fab32b5e8f36.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   Client   support   Mysql   nodejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104383文章数
  • 26212阅读数
  • 0评论数