無法連線到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>