errno:1251,sqlMessage:'客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端

errno:1251,sqlMessage:'客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端

问题描述:

我正在nodejs中创建简单的api项目. 为此,我已经安装了8.0.11版的mySql工作台. 我创建了配置文件dbConnection.js文件,并在dbconnection.js文件中编写了以下代码:

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;

并且我遇到以下错误:

代码:"ER_NOT_SUPPORTED_AUTH_MODE", errno:1251, sqlMessage:'客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端", sqlState:'08004', 致命:正确

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

注意:我已尽可能简化我的配置文件,即user = root,password = root,host = localhost.

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

打开终端并登录:

mysql -uroot -p

(然后输入您的密码)

之后:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

最后一件重要的事情是重置mysql服务:

And the last important thing is to reset mysql service:

sudo service mysql restart