Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errno: 1251, sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client

I'm creating the simple api project in nodejs.

For that I have installed mySql workbench with version 8.0.11. I have created config file, dbConnection.js file and in the dbconnection.js file I have written the following code :

var mysql = require('mysql');
var path = require('path');
var config = require(path.resolve('./', 'config'))

var connection = mysql.createConnection({
    host: config.databaseHost,
    user: config.databaseUser,
    password: config.databasePassword,
    database: config.databaseDatabaseName,
    multipleStatements: true
});

connection.connect(function (err) {
    if (err) {
        console.log('Error connecting to Database',err);
        return;
    }
    console.log('Connection established');
});
module.exports = connection;

And I'm facing following 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

Note : I kept my congif as simple as it can be, user = root , password = root, host = localhost.

like image 566
Pradnesh Shinde Avatar asked Jul 03 '18 06:07

Pradnesh Shinde


People also ask

Can't connect to specified instance MySQL error number 1251?

Error no. 1251: "Client does not support authentication protocol requested by server - consider upgrading MySQL client" occurs when the hashing-method for storing password used by the client differs from the one of the server.

How do I update MySQL workbench?

Step 2: Navigate to Software > MySQL Upgrade or type “MySQL” into the search bar. You may also find it under SQL Services > MySQL/MariaDB Upgrade. Step 3: Select the version of MySQL you want to upgrade to and click Next. Now follow the upgrade steps, and it'll take care of everything for you.


2 Answers

once you establish your host, root, password &, etc inside your MySQL connection function.. paste the following inside of your database you are trying to connect within workbench with the following:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_current_password';

Go back to the terminal and run node <file name.js> again

like image 143
Jackie Santana Avatar answered Oct 20 '22 00:10

Jackie Santana


Open terminal and login:

mysql -u root -p

(then type your password)

After that:

USE mysql;

UPDATE user SET authentication_string=password(''), plugin='mysql_native_password' WHERE user='root';

And the last important thing is to reset mysql service:

sudo service mysql restart
like image 21
Mohammad Raheem Avatar answered Oct 19 '22 23:10

Mohammad Raheem