简体   繁体   中英

Cannot connect to mysql on docker

This is my service definition:

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: "*"

If I connect to mysql from the docker, and run this:

SELECT host, user FROM mysql.user;

I get:

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

So it should be fine. Then if I run:

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

I have:

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                                          *

This also should be fine. Running netcat 172.30.0.3 3306 (ip address get through docker inspect), I have a response. But still, this gives me an error:

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

Try this format:

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

and make sure that the port is available on that IP.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM