Reputation: 297
Problem in mysql used in nodejs
const mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123456789',
database : 'userdata'
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err);
return;
}
console.log('connected as id ' + connection.threadId);
});
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Upvotes: 25
Views: 50162
Reputation: 1
someone can tell me how this command works?
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Upvotes: 0
Reputation: 1340
root
Password Hashing
to Native MySQL authentication
Upvotes: 2
Reputation: 11
update node-version to 16.X or greater and change the module from 'mysql/sync-mysql' to 'mysql2' in node api file
Upvotes: 1
Reputation: 81
In any database software (mysql workbench,datagrip, dbeaver...):
First run this query:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Second, if your problem still persists, run this query:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Combining and running these two queries separately worked for me with dockorize mysql.
Upvotes: 8
Reputation: 1119
You installed mysql server using "mysql installer"
1)open -> "mysql intsaller"
2)press reconfig mysql server
3)select left side "authentication method tab"
4)select radio button -->use legacy authentication method
5)now stop and restart the db
Thanks!
Upvotes: 10
Reputation: 508
Had the same problem.
Install MySQL Workbench
Execute this query: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456789';
in MySQL Workbench
Head back over to Node.js and try running the file again. It should work, at least it did for me.
Upvotes: 46