问题描述
node版本为8.9.2,连接mysql8.0,显示连接成功但是报错,报错为:Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
相关代码
const mysql = require('mysql')
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '123456',
database: 'test_self',
})
db.query('SELECT * FROM `users`', (err, data) => {
console.log('成功') // 这里可以打出'成功'
if (err) {
console.log(err) // 这里报错
} else {
console.log(data)
}
})
登录数据库的客户端跟mysql8.0不兼容了,mysql8.0密码认证采用了新的密码格式