无法连接到MySQL - 错误代码ER_NOT_SUPPORTED_AUTH_MODE
<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>