无法连接到MySQL - 错误代码ER_NOT_SUPPORTED_AUTH_MODE
P粉736935587
2023-08-26 15:09:04
<p>我在MySQL中创建了一个数据库,并想用JS连接它。下面是我为此编写的代码,但出现错误。</p>
<pre class="brush:php;toolbar:false;">const mysql = require('mysql');
var mysqlConnection = mysql.createConnection({
host: 'localhost',
user:'root',
password:'********',
database:'EmployeeDB'
});
mysqlConnection.connect((err) => {
if (!err)
console.log('DB Connection Succeded');
else
console.log('DB Connection Failed \n Error :'+ JSON.stringify(err, undefined, 2));
});</pre>
<p>我尝试更改主机的名称,并撤销和授予权限(都无法做到)。删除并重新创建数据库并再次尝试连接。我本来应该连接我的数据库,但它导致了一个我无法理解的错误。错误信息如下:</p>
<pre class="brush:php;toolbar:false;">DB Connection Failed
Error :{
"code": "ER_NOT_SUPPORTED_AUTH_MODE",
"errno": 1251,
"sqlMessage": "Client does not support authentication protocol requested by server; consider upgrading MySQL client",
"sqlState": "08004",
"fatal": true
}</pre>
<p>更改主机名后:</p>
<pre class="brush:php;toolbar:false;">DB Connection Failed
Error :{
"code": "ER_HOST_NOT_PRIVILEGED",
"errno": 1130,
"sqlMessage": "Host 'Mistycyrus.bbrouter' is not allowed to connect to this MySQL server",
"fatal": true
}</pre></p>
对于第一个错误“客户端不支持服务器请求的身份验证协议;考虑升级 MySQL 客户端”,您需要:
对于第二个错误“Host 'Mistycyrus.bbrouter' is not allowed to connect to this MySQL server”,您正在使用用户
'someone'@'Mistycyrus.bbrouter'
进行连接,并且该用户是不允许连接。127.0.0.1 localhost
。