Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.9k views
in Technique[技术] by (71.8m points)

node.js - MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

I can't make 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.

This is my node.js code

    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:Usersmysql-test>node app.js
    C:Usersmysql-test
ode_modulesmysqllibprotocolParse
    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:Usersmysql-
test
ode_modulesmysqllibprotocolsequencesSequence.js:52:14)
    at Handshake.ErrorPacket (C:Usersmysql-test
ode_mo
dulesmysqllibprotocolsequencesHandshake.js:130:18)
    at Protocol._parsePacket (C:Usersmysql-test
ode_mo
dulesmysqllibprotocolProtocol.js:279:23)
    at Parser.write (C:Usersmysql-test
ode_modulesmys
qllibprotocolParser.js:76:12)
    at Protocol.write (C:Usersmysql-test
ode_modulesm
ysqllibprotocolProtocol.js:39:16)
    at Socket.<anonymous> (C:Usersmysql-test
ode_modul
esmysqllibConnection.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:Usersmysql-test
ode_module
smysqllibprotocolProtocol.js:145:48)
    at Protocol.handshake (C:Usersmysql-test
ode_modul
esmysqllibprotocolProtocol.js:52:23)
    at Connection.connect (C:Usersmysql-test
ode_modul
esmysqllibConnection.js:130:18)
    at Object.<anonymous> (C:Usersmysql-testserver.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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Execute the following query in MYSQL Workbench

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

Where root as your user localhost as your URL and password as your password

Then run this query to refresh privileges:

flush privileges;

Try connecting using node after you do so.

If that doesn't work, try it without @'localhost' part.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...