关于 NodeJS 连接到 MySQL 8 出现 ER_NOT_SUPPORTED_AUTH_MODE 的问题
报错:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket. (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/Connection.js:88:28)
at Socket. (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:514:28)
at Socket.emit (node:domain:488:12)
--------------------
at Protocol._enqueue (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/Connection.js:116:18)
at Pool.getConnection (/Users/ivampiresp/Projects/express-ts-template/node_modules/mysql/lib/Pool.js:48:16)
at /Users/ivampiresp/Projects/express-ts-template/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:1268:18
at new Promise ()
at MysqlDriver.createPool (/Users/ivampiresp/Projects/express-ts-template/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:1265:16)
at MysqlDriver.connect (/Users/ivampiresp/Projects/express-ts-template/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:400:36)
at DataSource.initialize (/Users/ivampiresp/Projects/express-ts-template/node_modules/src/data-source/DataSource.ts:249:27)
at Object.handler (/Users/ivampiresp/Projects/express-ts-template/node_modules/src/commands/MigrationRunCommand.ts:52:30) {
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
}

找了一圈,发现都是治标不治本的,把 MySQL 的 caching_sha2_password 改成 mysql_native_password。

但是其实很简单,把 mysql 包卸了,换成 mysql2。但是这个得看你的项目来,我用的是 TypeORM,可以直接切换。

yarn remove mysql
yarn add mysql2
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇