连接数据库但是后台拿不到数据,输入后台端口路径一直加载且控制台输出“数据库语句错误
//封装数据库操作语句 sql语句 参数数组arr callback成功函数结果
function sqlFun(sql, arr,callback) {
client.query(sql,arr, function (error, result) {
if (error) {
console.log('数据库语句错误'); //因为写了这个语句所以只会打印“数据库语句错误”
return; //不显示具体错误
}
callback(result)
})
}
找错误办法
添加语句console.log(error); 也可以是找别的不报错但是结果不对的找错方法
//封装数据库操作语句 sql语句 参数数组arr callback成功函数结果
function sqlFun(sql, arr,callback) {
client.query(sql,arr, function (error, result) {
if (error) {
console.log('数据库语句错误');
console.log(error); //添加这句函数打印错误
return;
}
callback(result)
})
}
显示错误
解决MySQL8.0报错Client does not support authentication protocol requested by server; consider upgrading MySQL client问题
原创:丶无殇 2023-10-07
使用node.js连接数据库MySQL 8时候,报错ER_NOT_SUPPORTED_AUTH_MODE,并且提示Client does not support authentication protocol requested by server; consider upgrading MySQL client:客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端;
报错原因
最新的MySQL模块并未完全支持MySQL 8.0的caching_sha2_password加密方式,而MySQL 8.0中默认仍然是caching_sha2_password加密方式,因此用户认证不通过了。
如下查询:
1.mysql> alter user 'root'@'localhost' identified by '123456';
2.Query OK, 0 rows affected (0.02 sec)
这里的“123456”是你自己的密码
解决方法
直接数据库工具里面修改加密方式mysql_native_password:
或者通过指令方式修改:
1.mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
2.Query OK, 0 rows affected (0.01 sec)
数据库连接和关闭都成功,连接问题解决
参考文章:解决MySQL8.0报错Client does not support authentication protocol requested by server...问题