Nodejs MYSQL Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol (2024) | TechGeekNext

Nodejs MYSQL Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol (2024)

In this tutorial, we will help you to resolve the Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client issue.

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (D:\express-crud-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Handshake.ErrorPacket (D:\express-crud-mysql\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
    at Protocol._parsePacket (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (D:\express-crud-mysql\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (D:\express-crud-mysql\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    --------------------
    at Protocol._enqueue (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (D:\express-crud-mysql\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (D:\express-crud-mysql\node_modules\mysql\lib\Connection.js:116:18)
    at Object.<anonymous> (D:\express-crud-mysql\config\database-config.js:9:12)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  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

This problem occurs while using MySQL dependency. Currently, MySQL 8.0 default authentication plugin caching sha2 password is not supported by the mysql npm package.

Follow below steps to resolve Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client issue.

  1. Uninstall the mysql package from the application using npm uninstall mysql command.
  2. Install mysql2 using npm install mysql2 command.
  3. Change below code:
    From
    const mysql = require('mysql')
    To:
    const mysql = require('mysql2')
  4. Now start your application using npm start command and check the database connection.
  5. Follow Express MYSQL Crud Example to see database connection code.

Recommendation for Top Popular Post :