宿命论是那些缺乏意志力的弱者的借口。——罗曼·罗兰
今天试了试使用js
连接数据库,发现报错Client does not support authentication protocol requested by server; consider upgrading MySQL client
乍一看,代码好像没问题
var mysql = require("mysql");
let connection = mysql.createConnection({
host: "127.0.0.1",
port: 3306,
user: "root",
password: "789456",
database: "ruben"
});
connection.connect();
connection.query("select * from user", function (error, results, fields) {
if (error) throw error;
console.log(results);
console.log(fields);
});
connection.end();
但我的mysql版本是8.0.22
所以需要执行以下sql
alter user 'root'@'localhost' identified with mysql_native_password by '789456';
flush privileges;
然后就可以正常执行了
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有