0

I'm following a tutorial on the internet to learn MySQL through Node.js, but I'm unable to connect them. Here is the error I'm getting:

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

My code:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "*******"
});

con.connect(function(err) {
  if (err) console.log(err);
else 
  console.log("Connected!");
});

I have installed the MySQL driver using npm and I have just installed MySQL, what am I doing wrong?

2 Answers2

0

It appears that your MySQL installation and node's MySQL plugin used have incompatible authentication methods/protocols. Simplest solution is to "downgrade" the protocol used on the db server - start your mysql client via mysql command and execute the following:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
mysql> FLUSH PRIVILEGES;
Marek Piotrowski
  • 2,988
  • 3
  • 11
  • 16
0

Have you tried setting root password as null? [1]: How to set root password to null

Changing plugin to mysql_native_password may solved your problem.

MAK
  • 27
  • 4