Mysql: I'm getting ER_NOT_SUPPORTED_AUTH_MODE. Why?

Created on 9 Jun 2018  路  7Comments  路  Source: mysqljs/mysql

When I try to make a basic connection, it gives me this error:

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Handshake.ErrorPacket (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/sequences/Handshake.js:130:18)
    at Protocol._parsePacket (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/Connection.js:103:28)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:279:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    --------------------
    at Protocol._enqueue (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at Connection.connect (/Users/riverlewis/Desktop/node/mysql-test/node_modules/mysql/lib/Connection.js:130:18)
    at Object.<anonymous> (/Users/riverlewis/Desktop/node/mysql-test/app.js:11:5)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)

My code is

// app.js
const mysql = require('mysql');

// First you need to create a connection to the db
const con = mysql.createConnection({
  host: 'localhost',
  user: 'user',
  password: 'secret'
});

con.connect((err) => {
  if(err){
    throw err;
    }
  console.log('Connection established');
});

con.end((err) => {
  // The connection is terminated gracefully
  // Ensures all previously enqueued queries are still
  // before sending a COM_QUIT packet to the MySQL server.
});
duplicate

Most helpful comment

After looking at a comment on #1962, I can get it to work with what @ruiquelhas has done:

everything should still work if you use the mysql_native_password plugin.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';
-- or
CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';

However, it would be good for it to work without plugins.

All 7 comments

What is your server version? Mysql 8 switched to different default auth mode which is not yet supported by this library.

Possible duplicate of #2002

Mysql server is version 8.0.11.

After looking at a comment on #1962, I can get it to work with what @ruiquelhas has done:

everything should still work if you use the mysql_native_password plugin.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';
-- or
CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';

However, it would be good for it to work without plugins.

However, it would be good for it to work without plugins.

It's in progress, see #1962

@rivques Thank you so much! You fixed my bug :)

This line resolve my problem too,

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';

This line resolve my problem too,

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';

Hi Emanuel, Did you run this command on MySql Workbench?

Andrea

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JCQuintas picture JCQuintas  路  3Comments

ajpyoung picture ajpyoung  路  4Comments

Rhapsody-Sky picture Rhapsody-Sky  路  3Comments

EdoardoPedrotti picture EdoardoPedrotti  路  3Comments

nanom1t picture nanom1t  路  3Comments