Unable to connect to MySQL - error code ER_NOT_SUPPORTED_AUTH_MODE
P粉7369355872023-08-26 15:09:04
0
1
630
<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:
Make sure your DLL file "libmySQL.dll" is up to date.
Maybe your account was created with "Old Authentication Protocol Password" and the server now uses "New Authentication Protocol Password". See Documentation for information.
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.
Based on the word bbrouter it may be related to your router as I have seen something similar to a Thomson router before.
Check your hosts file. Make sure the hosts file contains the line 127.0.0.1 localhost.