简体   繁体   中英

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.

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

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

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!!

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

Was getting ERROR 1251 in node v17 with mysql

❌ // didn't worked: errno 1251 ER_NOT_SUPPORTED_AUTH_MODE

import mysql from 'mysql';

Try to remove mysql from node and replace it for mysql2

yarn remove 'mysql'
yarn add 'mysql2'
✅  import mysql2 from 'mysql2';

This fixed the issue for me!

Install mysql2 instead of mysql

npm install mysql2

Then add this to index.js

const mysql = require('mysql2')

I also had the same problem. It did not work for the root user. I created a new user (using mySQL workbench) and gave privileges to the new user. Then I tried with the new user and it worked fine. see workbench settings

Try to remove mysql

yarn remove mysql
yarn add mysql2
import mysql2 from "mysql2"

This fixed issue for me. code:

"ER_NOT_SUPPORTED_AUTH_MODE" errno: 1251 fatal: true sqlMessage: "Client does not support authentication protocol requested by server; consider upgrading MySQL client" sqlState: "08004"

Try this with your password and user name root if your password was not root try with your password. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM