我正在尝试设置一个应用程序,它有一个node.js服务器和一个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
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` 是设置吗?
1条答案
按热度按时间jgwigjjp1#
我想你最终还是要把事情搞清楚了
mysql:latest
docker映像,在本例中,它将来自8.0系列。问题是mysql 8.0现在使用的默认身份验证插件与所使用的community node.js驱动程序不兼容sequelize
.您应该按照这里描述的步骤来克服这个限制。
在您的情况下,除了授予特权之外,您还必须首先切换用户身份验证插件。