[英]Unable to login to a mysql container in docker
我正在尝试建立一个具有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
于mySQL的Dockerfile
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
的方式有问题吗?
我猜您最终将拉到mysql:latest
docker映像,在这种情况下,它将来自8.0系列。 问题是MySQL 8.0现在使用的默认身份验证插件与sequelize
使用的社区Node.js驱动程序不兼容。
您应按照此处描述的步骤克服该限制。
在您的情况下,除了授予特权外,您还必须首先切换用户身份验证插件。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'supersecretpassword';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.