安装egg-mysql配置完成后,启动项目报错
来源:7-3 使用egg-mysql插件操作数据库

时过境迁丶谁又能谈笑风声
2020-10-15
问题描述
本地mysql版本8.0.21, 安装egg-mysql后,也配置好了,启动项目就报错. 终端内可以连接mysql及操作数据库,workbench也可以链接. 就在yarn dev启动项目报错, 把config.detail.js下的mysql下的app改成false,就正常启动了.
config/plugin.js
‘use strict’;
const path = require(‘path’);
exports.validate = {
enable: true,
package: ‘egg-validate’,
};
exports.ejs = {
enable: true,
package: ‘egg-view-ejs’,
};
exports.auth = {
enable: false,
path: path.join(__dirname, ‘…/lib/plugin/egg-auth’),
};
exports.mysql = {
enable: true,
package: ‘egg-mysql’,
};
config/config.detail.js
/* eslint valid-jsdoc: “off” */
‘use strict’;
const path = require(‘path’);
/**
- @param {Egg.EggAppInfo} appInfo app info
/
module.exports = appInfo => {
/*- built-in config
- @type {Egg.EggAppConfig}
**/
const config = exports = {};
config.auth = {
exclude: [ ‘/home’, ‘/user’, ‘/login’, ‘logout’ ],
};
config.mysql = {
app: true,
agent: false,
client: {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: 'root',
database: 'egg',
},
};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + ‘_1602639504560_5566’;
// add your middleware config here
config.middleware = [ ‘httpLog’ ];
config.httpLog = {
type: ‘all’,
};
// add your user config here
const userConfig = {
// myAppName: ‘egg’,
};
config.security = {
csrf: {
enable: false,
},
};
config.view = {
mapping: {
’.ejs’: ‘ejs’,
},
// root: path.join(appInfo.baseDir, ‘app/html’),
root: [
path.join(appInfo.baseDir, ‘app/html’),
path.join(appInfo.baseDir, ‘app/view’),
].join(’,’),
};
config.ejs = {
delimiter: ‘$’,
};
config.static = {
prefix: ‘/assets/’, // 访问路径
dir: path.join(appInfo.baseDir, ‘app/assets’), // 本地资源目录
};
return {
…config,
…userConfig,
};
};
报错信息
2020-10-15 20:48:30,251 ERROR 12204 [-/127.0.0.1/-/0ms GET /] nodejs.ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol reque
sted by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket. (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:88:28)
at Socket. (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:203:13)
at addChunk (_stream_readable.js:295:12)
--------------------
at Protocol._enqueue (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Pool.js:48:16)
at E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:29:7
at new Promise ()
at Pool. (E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:12:10)
at Pool.ret [as getConnection] (E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:56:34)
at Pool.query (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Pool.js:202:8)
at E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:29:7
sql: select now() as currentTime;
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
name: "ER_NOT_SUPPORTED_AUTH_MODEError"
pid: 12204
hostname: LAPTOP-D3OGVPI4
2020-10-15 20:48:30,255 ERROR 12204 nodejs.ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider u
pgrading MySQL client
at Handshake.Sequence._packetToError (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket. (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:88:28)
at Socket. (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:203:13)
at addChunk (_stream_readable.js:295:12)
--------------------
at Protocol._enqueue (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Pool.js:48:16)
at E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:29:7
at new Promise ()
at Pool. (E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:12:10)
at Pool.ret [as getConnection] (E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:56:34)
at Pool.query (E:\Code\ReactEgg\egg-lesson\node_modules\mysql\lib\Pool.js:202:8)
at E:\Code\ReactEgg\egg-lesson\node_modules\pify\index.js:29:7
sql: select now() as currentTime;
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
name: "ER_NOT_SUPPORTED_AUTH_MODEError"
pid: 12204
hostname: LAPTOP-D3OGVPI4
2020-10-15 20:48:30,257 ERROR 12204 [app_worker] start error, exiting with code:1
2020-10-15 20:48:30,259 WARN 14168 [ClusterClient:Connection] socket is closed by other side while there were still unhandled data in the socket buffer
[2020-10-15 20:48:30.266] [cfork:master:10300] worker:12204 disconnect (exitedAfterDisconnect: false, state: disconnected, isDead: false, worker.disableRefork: true)
[2020-10-15 20:48:30.267] [cfork:master:10300] don’t fork, because worker:12204 will be kill soon
2020-10-15 20:48:30,267 INFO 10300 [master] app_worker#1:12204 disconnect, suicide: false, state: disconnected, current workers: [“1”]
[2020-10-15 20:48:30.273] [cfork:master:10300] worker:12204 exit (code: 1, exitedAfterDisconnect: false, state: dead, isDead: true, isExpected: false, worker.disableRefork: true)
2020-10-15 20:48:30,275 ERROR 10300 nodejs.AppWorkerDiedError: [master] app_worker#1:12204 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
at Master.onAppExit (E:\Code\ReactEgg\egg-lesson\node_modules\egg-cluster\lib\master.js:510:21)
at Master.emit (events.js:203:13)
at Messenger.sendToMaster (E:\Code\ReactEgg\egg-lesson\node_modules\egg-cluster\lib\utils\messenger.js:137:17)
at Messenger.send (E:\Code\ReactEgg\egg-lesson\node_modules\egg-cluster\lib\utils\messenger.js:102:12)
at EventEmitter. (E:\Code\ReactEgg\egg-lesson\node_modules\egg-cluster\lib\master.js:353:22)
at EventEmitter.emit (events.js:208:15)
at ChildProcess. (internal/cluster/master.js:188:13)
at Object.onceWrapper (events.js:291:20)
at ChildProcess.emit (events.js:203:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
name: "AppWorkerDiedError"
pid: 10300
hostname: LAPTOP-D3OGVPI4
2020-10-15 20:48:30,276 ERROR 10300 [master] app_worker#1:12204 start fail, exiting with code:1
2020-10-15 20:48:30,277 ERROR 10300 [master] exit with code:1
Error: E:\Code\ReactEgg\egg-lesson\node_modules\egg-bin\lib\start-cluster {“typescript”:false,“declarations”:true,“workers”:1,“baseDir”:“E:\Code\ReactEgg\egg-lesson”,“framework”:“E
:\Code\ReactEgg\egg-lesson\node_modules\egg”} exit with code 1
at ChildProcess. (E:\Code\ReactEgg\egg-lesson\node_modules\common-bin\lib\helper.js:56:21)
at Object.onceWrapper (events.js:291:20)
at ChildProcess.emit (events.js:203:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) {
code: 1
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Process finished with exit code 1
1回答
-
时过境迁丶谁又能谈笑风声
提问者
2020-10-15
在网上找到了一个解决方案,
node第一次连接mysql,报错Client does not support authentication protocol requested by server的问题
原因: 在项目里面通过npm install 安装的mysql和最新版本MySQL加密方式不同,导致连接失败。
在最新下载的MySql客户端版本使用的是caching_sha2_password加密方式,所以默认创建的root用户和密码都是这个加密方式。而npm包里的mysql模块还是使用原来的mysql_native_password加密方式,两者不互通,连接会报错。
解决方法: 将mysql的用户密码从caching_sha2_password加密方式改回mysql模块能支持的 mysql_native_password加密方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
如上,将密码123456的认证修改成mysql_native_password,之后再连接mysql就会成功
622022-03-01
相似问题