无法连接到docker上的mysql

时间:2018-10-25 14:43:10

标签: mysql docker

这是我的服务定义:

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(IP地址通过docker inspect获得),我有一个响应。 但这仍然给我一个错误:

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

1 个答案:

答案 0 :(得分:0)

尝试这种格式:

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