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

限于喜欢 提交于 2020-07-17 13:58:39

问题


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 have kept my congif as simple as it can be, user = root , password = root , host = localhost.


回答1:


Open terminal and login:

mysql -uroot -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



回答2:


once you establish you host, root, password &, etc inside your MySQL connection function.. paste the following inside of your database you are trying to connect within workbench 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




回答3:


You have to reconfigure MySQL Server. for that follow these steps.

1) Open mysql intsaller.

2) Click on Reconfigure (to the left mysql server)

3) Go to Authentication method tab (by clicking on Next twice.)

4) Then select the radio button Use Legacy Authentication Method. Click Next.

5) Enter your password. Click on Check. Go to Apply Configuration (by clicking on Next twice).

6) Click on Execute. Then Finish.

That's it. Enjoy Hacking!!




回答4:


I also had the same problem. Still it's not work for root user. I created a new user (from mySql workbench) and give privileges to new user. Then I tried with this new user and it works fine. see workbench settings




回答5:


ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'current password';


来源:https://stackoverflow.com/questions/51147964/errno-1251-sqlmessage-client-does-not-support-authentication-protocol-reques

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!