Unable to connect to MySQL - error code ER_NOT_SUPPORTED_AUTH_MODE
P粉736935587
2023-08-26 15:09:04
<p>I have created a database in MySQL and want to connect to it using JS. Below is the code I wrote for this, but I'm getting an error. </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>I tried changing the name of the host and revoking and granting permissions (neither could be done). Drop and re-create the database and try connecting again. I'm supposed to connect to my database but it's causing an error that I can't understand. The error message is as follows: </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>After changing the hostname:</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>
For the first error "The client does not support the authentication protocol requested by the server; consider upgrading the MySQL client", you need to:
For the second error "Host 'Mistycyrus.bbrouter' is not allowed to connect to this MySQL server", you are connecting using user
'someone'@'Mistycyrus.bbrouter'
and that The user is not allowed to connect.127.0.0.1 localhost
.