node 链接 mysql 报错
error: 如下:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket. (D:\workspace\node\demo1\node_modules\mysql\lib\Connection.js:91:28)
at Socket. (D:\workspace\node\demo1\node_modules\mysql\lib\Connection.js:525:10)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
--------------------
at Protocol._enqueue (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\workspace\node\demo1\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\workspace\node\demo1\node_modules\mysql\lib\Connection.js:119:18)
at Object. (D:\workspace\node\demo1\mysqlConnect.js:9:12)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
原因:登录数据库的客户端跟 mysql8.0 不兼容了,mysql8.0 密码认证采用了新的密码格式
解决办法:
在系统 mysql 终端输入下面命令
//password 是你的数据库账户密码,root和host也是
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
原文地址 blog.csdn.net
评论区