Midway + TypeORM项目部署到BT后启动失败,MySQL报错
前沿
您需要先了解这篇文章:https://blog.csdn.net/weixin_45687201/article/details/139336111
错误日志
- 服务状态开启后就失败
- 项目日志,输出
\> my-midway-project@1.0.0 start
\> cross-env NODE_ENV=production node ./bootstrap.js
2024-06-21 16:51:00.709 ERROR 16665 Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence.\_packetToError (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol.\_parsePacket (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser.\_parsePacket (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/www/wwwroot/web/midway-project/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/www/wwwroot/web/midway-project/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)---at Protocol.\_enqueue (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/www/wwwroot/web/midway-project/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/www/wwwroot/web/midway-project/node_modules/mysql/lib/Connection.js:116:18)
at Pool.getConnection (/www/wwwroot/web/midway-project/node_modules/mysql/lib/Pool.js:48:16)
at /www/wwwroot/web/midway-project/node_modules/typeorm/driver/mysql/MysqlDriver.js:1012:18
at new Promise (<anonymous>)
at MysqlDriver.createPool (/www/wwwroot/web/midway-project/node_modules/typeorm/driver/mysql/MysqlDriver.js:1009:16)
at MysqlDriver.connect (/www/wwwroot/web/midway-project/node_modules/typeorm/driver/mysql/MysqlDriver.js:305:36)
at DataSource.initialize (/www/wwwroot/web/midway-project/node_modules/typeorm/data-source/DataSource.js:136:27)
at TypeORMDataSourceManager.createDataSource (/www/wwwroot/web/midway-project/node_modules/@midwayjs/typeorm/dist/dataSourceManager.js:31:26) {
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
}
2024-06-21 16:51:00.710 INFO 16665 [midway:bootstrap] exit with code:1
抓住关键信息:
# 客户端不支持服务器请求的认证协议;考虑升级MySQL客户端
qlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client'
解决方案
更改用户认证插件
输入root用户的密码登录MySQL
# 这里使用之前创建的 Vinca 用户进行登录
sudo mysql -u root -p
更改用户认证插件
代码示例:
# 将'your_mysql_username', 'localhost', 'your_mysql_password'替换为实际的MySQL用户名,主机和密码。
ALTER USER 'your_mysql_username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_mysql_password';
如下实际应用场景操作:
# 将用户名为 Vinca 的用户的认证插件更改为 mysql_native_password
mysql> alter user 'Vinca'@'%' identified with mysql_native_password by 'Ecs@123****';# 刷新权限
mysql> flush privileges;# 退出 MySQL
mysql> exit;
开启服务
回到BT > 网站 > Node项目 > midwayService设置 > 服务状态(开启)
配置nginx
服务开启正常,但api接口依旧无法访问,您需要配置nginx的反向代理。
nginx反向代理:https://blog.csdn.net/weixin_45687201/article/details/139060839
server {listen 80;server_name your_domain.com;location / {proxy_pass http://localhost:7001;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_cache_bypass $http_upgrade;}
}
将上述配置保存为一个 .conf
文件,然后将其放置到 Nginx
的配置目录下,通常是 /etc/nginx/conf.d/
目录。
最后,重新加载 Nginx 配置即可生效:
sudo systemctl reload nginx
现在,你应该能够通过 API Post 请求访问你的 Midway 项目了。请确保替换 your_domain.com
为你的域名或 IP 地址。
参考链接: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client