1

I'm trying to connect to database from my node.js code and from SQLTools in VS Code.

Both in code and in settings I keep receiving error in SQLTools settings:

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

And from CMD:

Error connecting to the MySQL Database
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Sequence._packetToError (D:\Backend\Server\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Handshake.ErrorPacket (D:\Backend\Server\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
    at Protocol._parsePacket (D:\Backend\Server\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (D:\Backend\Server\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (D:\Backend\Server\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (D:\Backend\Server\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (D:\Backend\Server\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (D:\Backend\Server\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (node:events:537:28)
    at addChunk (node:internal/streams/readable:324:12)
    --------------------
    at Protocol._enqueue (D:\Backend\Server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (D:\Backend\Server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (D:\Backend\Server\node_modules\mysql\lib\Connection.js:116:18)
    at Object.<anonymous> (D:\Backend\Server\serverTest.js:9:12)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module: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

SQL Server path is added as environmental variable

enter image description here

I read I need to execute following command in sql query

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

from this SO question, but it didn't help me

enter image description here

enter image description here

And in addition here is the code:

serverTest.js:

const mysql = require('mysql')

const connection = mysql.createConnection({
      host: 'localhost',
      user: 'root@localhost',
      password: '135794ee497531E',
})

connection.connect(err => {
      if (err) {
            console.log('Error connecting to the MySQL Database')
            console.log(err)
            return
      }
      console.log('Connection established successfully!')
})

connection.end()
Lvasche
  • 91
  • 1
  • 9

1 Answers1

0

NOTE: to prevent your MySQL80 service from stopping without ability to start again, you should enter your current sql name CREATE USER 'root':

CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

Source: https://www.youtube.com/watch?v=b4m-BpJQHGA

To fix this error go to CMD and enter following command: mysql -u root -p

After you entered, write three commands step by step:

CREATE USER 'sqluser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

where you can write your parameters instead of sqluser and password

After this command executed, write

GRANT ALL PRIVILEGES ON . TO 'sqluser'@'%';

And finish with

FLUSH PRIVILEGES;
Lvasche
  • 91
  • 1
  • 9