[翻译]  MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

[CHINESE]  MySQL 8.0 - 客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端


I am a node.js and MySQL beginner and I just started setting up and trying out some basic code. However, I can't make even a simple connection to the server for some reason. I install the newest MySQL Community 8.0 database along with Node.JS with default settings.

我是node.js和MySQL初学者,我刚开始设置并尝试一些基本代码。但是,由于某种原因,我甚至无法与服务器建立简单的连接。我使用默认设置安装最新的MySQL Community 8.0数据库和Node.JS。

This is my node.js code

这是我的node.js代码

    var mysql = require('mysql');

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

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

Below is the error found in Command Prompt:

以下是命令提示符中发现的错误:

C:\Users\mysql-test>node app.js
    C:\Users\mysql-test\node_modules\mysql\lib\protocol\Parse
    r.js:80
            throw err; // Rethrow non-MySQL errors
            ^

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (C:\Users\mysql-
test\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
    at Handshake.ErrorPacket (C:\Users\mysql-test\node_mo
dules\mysql\lib\protocol\sequences\Handshake.js:130:18)
    at Protocol._parsePacket (C:\Users\mysql-test\node_mo
dules\mysql\lib\protocol\Protocol.js:279:23)
    at Parser.write (C:\Users\mysql-test\node_modules\mys
ql\lib\protocol\Parser.js:76:12)
    at Protocol.write (C:\Users\mysql-test\node_modules\m
ysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\Users\mysql-test\node_modul
es\mysql\lib\Connection.js:103:28)
    at Socket.emit (events.js:159:13)
    at addChunk (_stream_readable.js:265:12)
    at readableAddChunk (_stream_readable.js:252:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    --------------------
    at Protocol._enqueue (C:\Users\mysql-test\node_module
s\mysql\lib\protocol\Protocol.js:145:48)
    at Protocol.handshake (C:\Users\mysql-test\node_modul
es\mysql\lib\protocol\Protocol.js:52:23)
    at Connection.connect (C:\Users\mysql-test\node_modul
es\mysql\lib\Connection.js:130:18)
    at Object.<anonymous> (C:\Users\mysql-test\server.js:
11:5)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)

I've read up on some things such as: https://dev.mysql.com/doc/refman/5.5/en/old-client.html https://github.com/mysqljs/mysql/issues/1507

我已经阅读了一些内容,例如:https://dev.mysql.com/doc/refman/5.5/en/old-client.html https://github.com/mysqljs/mysql/issues/1507

But I am still not sure how to fix my problem. Any help would be appreciated :D

但我仍然不确定如何解决我的问题。任何帮助将不胜感激:D

4 个解决方案

#1


38  

Execute the following query in MYSQL Workbench

在MYSQL Workbench中执行以下查询

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

ALTER USER'root'@'localhost'用mysql_native_password识别BY'密码'

Try connecting using node after you do so

在执行此操作后尝试使用节点进行连接

#2


0  

Just Run MySQL Server Installer and Reconfigure the My SQL Server...This worked for me.

只需运行MySQL Server Installer并重新配置My SQL Server ......这对我有用。

#3


0  

I have the same problem with MySQL and I solve by using XAMPP to connect with MySQL and stop the services in windows for MySQL (control panel - Administrative Tools - Services), and in the folder db.js (that responsible for the database ) I make the password empty (here you can see:)

我有与MySQL相同的问题,我通过使用XAMPP连接MySQL并在Windows for MySQL(控制面板 - 管理工具 - 服务)和文件夹db.js(负责数据库)中停止服务来解决将密码设为空(在这里你可以看到:)

const mysql = require('mysql');
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: ''
});

#4


0  

Original documentation you can find here : https://dev.mysql.com/doc/dev/connector-nodejs/8.0/

您可以在此处找到原始文档:https://dev.mysql.com/doc/dev/connector-nodejs/8.0/

'use strict';

const mysqlx = require('@mysql/xdevapi');

const options = {
  host: 'localhost',
  port: 33060,
  password: '******',
  user: 'root',
  schema: 'yourconference'
};

mysqlx.getSession(options)
  .then(session => {
          console.log(session.inspect());
           session.close();
  }).catch(err => {
    console.error(err.stack);
    process.exit(1);
  });

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号