我尝试将一个包含node.js应用程序的项目对接到mysql数据库。
两个容器都启动,但节点容器始终获得“SequelizeAccessDeniedError”
> scrumboard-app@1.0.0 start
> node app.js
Use no environment variables
{
username: 'scrumboard',
password: 'scrumboard',
database: 'scrumboard',
host: 'mysql',
dialect: 'mysql',
port: 3306,
operatorsAliases: false
}
(node:20) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
(Use `node --trace-deprecation ...` to show where the warning was created)
server is running on port 3000
Unhandled rejection SequelizeAccessDeniedError: Access denied for user 'scrumboard'@'172.23.0.3' (using password: YES)
at /scrumboard-app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:125:19
at tryCatcher (/scrumboard-app/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/scrumboard-app/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/scrumboard-app/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/scrumboard-app/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/scrumboard-app/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/scrumboard-app/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/scrumboard-app/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/scrumboard-app/node_modules/bluebird/js/release/async.js:102:5)
at Async.drainQueues [as _onImmediate] (/scrumboard-app/node_modules/bluebird/js/release/async.js:15:14)
at process.processImmediate (node:internal/timers:471:21)
a user is connected
mysql容器也是这么说的:
2022-11-29T15:11:59.491328Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2022-11-29T15:11:59.491368Z 0 [Note] IPv6 is available.
2022-11-29T15:11:59.491377Z 0 [Note] - '::' resolves to '::';
2022-11-29T15:11:59.491389Z 0 [Note] Server socket created on IP: '::'.
2022-11-29T15:11:59.495079Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-11-29T15:11:59.499174Z 0 [Note] Event Scheduler: Loaded 0 events
2022-11-29T15:11:59.499449Z 0 [Note] mysqld: ready for connections.
Version: '5.7.40' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2022-11-29T15:12:00.101178Z 2 [Note] Access denied for user 'scrumboard'@'172.23.0.3' (using password: YES)
所以看起来他们之间的沟通是有效的。
这是我的docker-compose文件:
version: '3.8'
services:
mysql:
image: mysql:5.7
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=scrumboard
- MYSQL_PASSWORD=scrumboard
- MYSQL_DATABASE=scrumboard
- MYSQL_USER=scrumboard
ports:
- 3306:3306
# [HOST:]CONTAINER
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysql
build: ./scrumboard-app
restart: unless-stopped
env_file: ./.env
ports:
- 3000:3000
stdin_open: true
tty: true
volumes:
db:
这是sequelize使用的配置文件:
"development": {
"username": "scrumboard",
"password": "scrumboard",
"database": "scrumboard",
"host": "mysql",
"dialect": "mysql",
"port": 3306,
"operatorsAliases": false
}
这是建立与数据库连接的代码:
const config = require(__dirname + '/../config/config.json')[env];
let sequelize;
console.info('Use no environment variables');
console.info(config);
sequelize = new Sequelize(config.database, config.username, config.password, config);
我不知道这里出了什么问题,因为我三次检查了用户名、密码等。你知道问题出在哪里吗?
1条答案
按热度按时间mklgxw1f1#
我猜是不允许用户从外部连接?
你能查一下
您应该可以在那里看到您的用户,并且该用户不应该被锁定或过期。
此外,主机应匹配IP 172.23.0.3或匹配IP的通配符。
要允许从任何位置连接到您的用户,您可以执行以下操作:
请注意,此查询将授予对所有内容的所有权限。最好先进行测试,以便我们可以对您的连接进行故障排除,但随后应设置适当的权限。
如果仍然无法连接,请检查您是否可以直接从mysql容器内部连接,如果可以,这至少意味着凭据是有效的。如果不能,您需要尝试重置密码,再次检查用户名等。