我正在尝试建立一个具有1个node.js服务器和1个mysql数据库的应用程序。我正在尝试将其与docker集成。我在尝试从node.js应用程序登录mysql时遇到问题。
简而言之-这是我的docker-compose.yml
文件
version: '2.1'
services:
db:
build: ./db
restart: always
environment:
# - MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=subscriptions
- MYSQL_PASSWORD=supersecretpassword
- MYSQL_ROOT_PASSWORD=supersecretpassword
- MYSQL_USER=root
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 30s
timeout: 1s
retries: 1
subscription_api:
build: ./subscription_api_server
restart: always
depends_on:
db:
condition: service_healthy
ports:
- "5000:5000"
我的Dockerfile
for mySQL
CREATE DATABASE IF NOT EXISTS subscriptions;
grant all privileges on *.* to root@localhost identified by 'supersecretpassword' with grant option;
FLUSH PRIVILEGES;
我的node.js应用程序使用sequelize
作为ORM,并在config.js
此处指定了连接字符串
"development": {
"username": "root",
"password": "supersecretpassword",
"database": "subscriptions",
"host": "db",
"dialect": "mysql"
},
运行docker-compose up
时-我的node.js
应用程序出现以下错误
subscription_api_1 | Sequelize CLI [Node: 10.12.0, CLI: 5.1.0, ORM: 4.39.0]
subscription_api_1 |
subscription_api_1 | Loaded configuration file "config/config.json".
subscription_api_1 | Using environment "development".
subscription_api_1 | Sun, 14 Oct 2018 17:50:17 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:242:13
subscription_api_1 |
subscription_api_1 | ERROR: Client does not support authentication protocol requested by server; consider upgrading MySQL client
但是当我尝试直接ssh进入我的docker容器时,用户名/密码有效
sudo docker exec -it fullstack-dev-assignment_db_1 bash
root@d36f499b706e:/# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@d36f499b706e:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
我设置sequelize
的方式有问题吗?
答案 0 :(得分:0)
我猜您最终将获得mysql:latest
泊坞窗映像,在这种情况下,该映像将来自8.0系列。问题是MySQL 8.0现在使用的默认身份验证插件与sequelize
使用的社区Node.js驱动程序不兼容。
您应按照here所述的步骤来克服该限制。
在您的情况下,除了授予特权之外,您还必须首先切换用户身份验证插件。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'supersecretpassword';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;