本地使用docker-compose启动了一个mysql服务, 默认使用image tag 是latest, yaml文件以下:html
## 本地开发所需资源文件 version: '3' services: ### mysql (https://hub.docker.com/_/mysql/) db_mysql: container_name: mysql environment: MYSQL_ROOT_PASSWORD: 1qaz TZ: Asia/Shanghai image: mysql ports: - 3306:3306 restart: always
nodejs 程序使用typeorm和以下配置连接本地mysql:node
DB_TYPE=mysql DB_HOST=localhost DB_PORT=3306 DB_USERNAME=root DB_PASSWORD=1qaz DB_DATABASE=test DB_SYNC=true
启动程序报告错误:mysql
{ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client at Handshake.Sequence._packetToError (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14) ... ...
问题定义: mysql client 连接 mysql server 出现权限验证方面错误git
MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client : 该方案实际执行sql脚本, 可是不work.github
ER_NOT_SUPPORTED_AUTH_MODE after upgrade: 该方案也是执行sql修改root用户权限, github上不少尝试后好用, 采纳该方案, 结果是work, 到此问题解决.sql
ER_NOT_SUPPORTED_AUTH_MODE - MySQL server: 该方案经过开启insecureAuth, 感受不太安全而且问题在上一步获得解决没有采纳.docker
根本缘由: mysql的client驱动当前仅支持 mysql_native_password/mysql_old_password 鉴权模式, 而5.7后默认的鉴权模式是: plugin, mysql提供两个插件:安全
mysql8.0默认用的是: caching_sha2_password而不是mysql_native_password, 咱们的解决方案则是修改root用户鉴权模式从caching_sha2_password为传统的mysql_native_password.app
经过查询用户信息:socket
mysql> select Host,User,plugin,authentication_string from user where User='root'\G *************************** 1. row *************************** Host: localhost User: root plugin: auth_socket authentication_string: 1 row in set (0.00 sec)
本质上应该使得client driver支持auth_socket.
方案一: 连接到mysql server, 执行以下命令:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
方案二: 设置docker启动命令, 采用native password
db_mysql: container_name: mysql environment: MYSQL_ROOT_PASSWORD: 1qaz TZ: Asia/Shanghai image: mysql command: --default-authentication-plugin=mysql_native_password ports: - 3306:3306 restart: always
重启nodejs服务没有错误了, 问题解决!