mysql Client does not support authentication protocol requested by server error in both js code and sql tools in vscode

km0tfn4u  于 2023-04-10  发布在  Mysql
关注(0)|答案(1)|浏览(199)

我正在尝试从我的node.js代码和VS Code中的SQLTools连接到数据库。
在代码和设置中,我一直在SQLTools设置中收到错误:

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

来自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路径作为环境变量添加

我读到我需要在sql查询中执行以下命令

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

this所以问题,但它没有帮助我

下面是代码:

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()
nhhxz33t

nhhxz33t1#

来源:https://www.youtube.com/watch?v=b4m-BpJQHGA
要修复此错误,请转到CMD并输入以下命令:mysql -u root -p
输入后,一步一步写三个命令:

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

在这里你可以写你的参数而不是sqluserpassword
执行此命令后,写入

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

最后以

FLUSH PRIVILEGES;

相关问题