admin管理员组文章数量:1241084
In a node project I create a basic mysql container exposing the 3307 port because the 3306 is already occupied by the local MySQL server. Apparently it all runs fine, but I'm unable to connect with workbench to it. I checked the firewall's rules, added a wide one, and removed all related to docker so that it prompted me again to accept them, but when try to connect with both "user" or "root" it responds "Access denied for user 'user'@'172.18.0.1' using password yes". With 172.18.0.1 being the docker's bridge. I'm out of ideas.
The docker-compose.yml
version: '3.9'
services:
db:
image: mysql:8.3.0
container_name: mysql-db
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
ports:
- ${DB_PORT}:3306
expose:
- 3307
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
and these variables in the .env file
NODE_ENV=development
DB_HOST=localhost
DB_USER=user
DB_PASSWORD=supersecret
DB_NAME=test_database
DB_PORT=3307
and this is the log
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql-db | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
mysql-db | 2025-02-19T08:17:28.637905Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql-db | 2025-02-19T08:17:28.847850Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.3.0) starting as process 1
mysql-db | 2025-02-19T08:17:28.854518Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-db | 2025-02-19T08:17:28.982700Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-db | 2025-02-19T08:17:29.138583Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql-db | 2025-02-19T08:17:29.138633Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql-db | 2025-02-19T08:17:29.141681Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql-db | 2025-02-19T08:17:29.162045Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql-db | 2025-02-19T08:17:29.162170Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.3.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
and this is docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fda5732ca548 mysql:8.3.0 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 3307/tcp, 33060/tcp, 0.0.0.0:3307->3306/tcp mysql-db
and this is the netstat -ano | findstr :3307
TCP 0.0.0.0:3307 0.0.0.0:0 LISTENING 6884
TCP [::]:3307 [::]:0 LISTENING 6884
TCP [::1]:3307 [::]:0 LISTENING 8324
In a node project I create a basic mysql container exposing the 3307 port because the 3306 is already occupied by the local MySQL server. Apparently it all runs fine, but I'm unable to connect with workbench to it. I checked the firewall's rules, added a wide one, and removed all related to docker so that it prompted me again to accept them, but when try to connect with both "user" or "root" it responds "Access denied for user 'user'@'172.18.0.1' using password yes". With 172.18.0.1 being the docker's bridge. I'm out of ideas.
The docker-compose.yml
version: '3.9'
services:
db:
image: mysql:8.3.0
container_name: mysql-db
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
ports:
- ${DB_PORT}:3306
expose:
- 3307
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
and these variables in the .env file
NODE_ENV=development
DB_HOST=localhost
DB_USER=user
DB_PASSWORD=supersecret
DB_NAME=test_database
DB_PORT=3307
and this is the log
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-db | 2025-02-19 08:17:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql-db | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
mysql-db | 2025-02-19T08:17:28.637905Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql-db | 2025-02-19T08:17:28.847850Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.3.0) starting as process 1
mysql-db | 2025-02-19T08:17:28.854518Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-db | 2025-02-19T08:17:28.982700Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-db | 2025-02-19T08:17:29.138583Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql-db | 2025-02-19T08:17:29.138633Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql-db | 2025-02-19T08:17:29.141681Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql-db | 2025-02-19T08:17:29.162045Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql-db | 2025-02-19T08:17:29.162170Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.3.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
and this is docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fda5732ca548 mysql:8.3.0 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 3307/tcp, 33060/tcp, 0.0.0.0:3307->3306/tcp mysql-db
and this is the netstat -ano | findstr :3307
TCP 0.0.0.0:3307 0.0.0.0:0 LISTENING 6884
TCP [::]:3307 [::]:0 LISTENING 6884
TCP [::1]:3307 [::]:0 LISTENING 8324
Share
Improve this question
asked 18 hours ago
FehuFehu
4011 gold badge4 silver badges19 bronze badges
4
|
1 Answer
Reset to default 1First connect to your docker container, via
docker exec -it <the hash> mysql -u <your username> -p
and when prompted, type in the password. Then run
select user, host
from mysql.user
where user = '<your username>';
In the result you will see what hosts are supported, likely %
and localhost
. Then create a user with the host you want and grant privileges to it:
CREATE USER 'yourusername'@'172.18.0.1' IDENTIFIED BY 'yourpassword';
GRANT SELECT, INSERT, UPDATE, DELETE on MyDatabse.* to 'yourusername'@'172.18.0.1';
FLUSH PRIVILEGES;
本文标签: windowsUnable to connect to mysql container from workbenchStack Overflow
版权声明:本文标题:windows - Unable to connect to mysql container from workbench - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740023276a2220881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
db_data
volume that contains the database data. Try bringing the containers down withdocker compose down -v
. The-v
option will delete the named volumes. Then bring it up again and you should get a fresh database. – Hans Kilian Commented 16 hours ago