gpt4 book ai didi

mysql - 无法连接到docker上的mysql

转载 作者:行者123 更新时间:2023-11-30 21:38:05 26 4
gpt4 key购买 nike

这是我的服务定义:

version: "3"
services:
rabbit:
image: rabbitmq:management
ports:
- "5672:5672"
# - "15672:15672"
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: eventstore
MYSQL_ROOT_HOST: "*"

如果我从 docker 连接到 mysql,然后运行:

SELECT host, user FROM mysql.user;

我得到:

+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+

所以应该没问题。然后如果我运行:

mysqld --verbose --help | grep bind-address

我有:

mysqld --verbose --help | grep bind-address
2018-10-25T14:40:08.820014Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
--bind-address=name IP address to bind to.
--mysqlx-bind-address[=name]
bind-address 0.0.0.0
mysqlx-bind-address *

这也应该没问题。运行 netcat 172.30.0.3 3306(通过 docker inspect 获取的 ip 地址),我有一个响应。但是,这仍然给我一个错误:

mysql -u root 172.30.0.3 -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

最佳答案

试试这个格式:

mysql -u {username} -p {password} -h {remote server ip or name} -P {port} 

并确保端口在该 IP 上可用。

mysql -u root -p -h 172.30.0.3 -P 3306

关于mysql - 无法连接到docker上的mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52992071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com