错误信息:Client does not support authentication protocol requested by server; consider upgrading MySQL client
解决方案 打开DBeaver,运行以下sql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '要重置的密码';
再次运行node.js, 成功连接上数据库
const mySql =require('mysql')const db = mySql.createConnection({host:"localhost",user:"root",password:"19980404",database:"sys"})
db.connect()
db.query('select * from user',(err, data)=>{if(err){
console.log(err);return console.log('查询失败')}
console.log(data);})