-1

I have tried to execute the code below and I get an error message

var mysql = require('mysql');

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

connection.connect(function(err) {
    if (err) throw err;
    console.log("Connected To the Database");
});

error message:

/Users/joshnomso/node_modules/mysql/lib/protocol/Parser.js:437 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 (/Users/joshnomso/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14) at Handshake.ErrorPacket (/Users/joshnomso/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18) at Protocol._parsePacket (/Users/joshnomso/node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (/Users/joshnomso/node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (/Users/joshnomso/node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (/Users/joshnomso/node_modules/mysql/lib/protocol/Protocol.js:38:16) at Socket. (/Users/joshnomso/node_modules/mysql/lib/Connection.js:88:28) at Socket. (/Users/joshnomso/node_modules/mysql/lib/Connection.js:526:10) at Socket.emit (events.js:315:20) at addChunk (internal/streams/readable.js:309:12) -------------------- at Protocol._enqueue (/Users/joshnomso/node_modules/mysql/lib/protocol/Protocol.js:144:48) at Protocol.handshake (/Users/joshnomso/node_modules/mysql/lib/protocol/Protocol.js:51:23) at Connection.connect (/Users/joshnomso/node_modules/mysql/lib/Connection.js:116:18) at Object. (/Users/joshnomso/.git/nodemysql/hello.js:9:5) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47 { 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

please how can i resolve this

JoshNomso
  • 1
  • 2
  • Hi and welcome. A quick search using that error code came up with this: https://stackoverflow.com/questions/44946270/er-not-supported-auth-mode-mysql-server - which also links to other places this question has been asked. – Jerry Apr 01 '21 at 23:35
  • 1
    I should add that the fundamental problem is that MySQL 8 has changed its default authentication and if your client software is out of date, you will need to either update your tools or tell MySQL to use its old authentication method. – Jerry Apr 01 '21 at 23:42

1 Answers1

0

I found a solution

firstly installed mysql2 using npm install mysql2

then I changed the code to use mysql2

var mysql = require('mysql2');

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

con.connect(function(err) {
    if (err) throw err;
    console.log('Hello world! connected to database!');
});

An in-depth explanation of the cause of the problem is found here: MSQL8 password auth issue

JoshNomso
  • 1
  • 2