recherche

Maison  >  Questions et réponses  >  le corps du texte

Docker:无法连接容器中的mysql

1

2

3

4

5

6

7

8

9

<code>$ mysql -uroot -p -h192.168.99.100 -P3306       

Enter password:

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.99.100' (61)

 

$ mysqladmin -h192.168.99.100 --port=3306 version                                                                                                                                                      127 ↵

mysqladmin: connect to server at '192.168.99.100' failed

error: 'Can't connect to MySQL server on '192.168.99.100' (61)'

Check that mysqld is running on 192.168.99.100 and that the port is 3306.

You can check this by doing 'telnet 192.168.99.100 3306'</code>

DEBUG的过程

1

2

3

<code>$ docker ps -l

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES

b20584bc086e        sunzy/mysql         "/usr/bin/mysqld_safe"   21 minutes ago      Up 21 minutes       0.0.0.0:3306->3306/tcp   mysql</code>

1

2

3

4

5

6

<code>$ docker-machine ls

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM

default   *        virtualbox   Running   tcp://192.168.99.100:2376  

$ docker-machine ls

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM

default   *        virtualbox   Running   tcp://192.168.99.100:2376   </code>

1

2

3

4

5

<code>$ ping 192.168.99.100                                                                                                                                                                                    1 ↵

PING 192.168.99.100 (192.168.99.100): 56 data bytes

64 bytes from 192.168.99.100: icmp_seq=0 ttl=64 time=0.347 ms

64 bytes from 192.168.99.100: icmp_seq=1 ttl=64 time=0.388 ms

64 bytes from 192.168.99.100: icmp_seq=2 ttl=64 time=0.272 ms</code>

1

2

3

4

<code>$ telnet 192.168.99.100 3306                                                                                                                                                                             1 ↵

Trying 192.168.99.100...

telnet: connect to address 192.168.99.100: Connection refused

telnet: Unable to connect to remote host</code>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<code># mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

mysql> </code>

1

2

3

4

5

6

7

8

9

10

11

<code>mysql> select user,host,password from mysql.user;

+------------------+--------------+-------------------------------------------+

| user             | host         | password                                  |

+------------------+--------------+-------------------------------------------+

| root             | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root             | e611e15f9c9d | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root             | 127.0.0.1    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root             | ::1          |                                           |

| debian-sys-maint | localhost    | *1BD91232C0D2D2B5500129217CEF09B7EE71ABEC |

| root             | %            | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+------------------+--------------+-------------------------------------------+</code>

天蓬老师天蓬老师2896 Il y a quelques jours1639

répondre à tous(3)je répondrai

  • 高洛峰

    高洛峰2017-04-22 09:01:30

    Soudain, je me suis souvenu que j'avais rencontré cette situation avant d'utiliser vagrant, mais le rapport était 2013-Connexion perdue au serveur MySQL lors de la « lecture du paquet de communication initialErreur=>

    1. Ouvrez le fichier de configuration MySQL

      sudo vim /etc/mysql/my.cnf

    2. Trouvez

      bind-address, changez 127.0.0.1 en 0.0.0.0 ou commentez la ligne

    3. Redémarrez MySQL

    Je l'ai essayé et ça a bien fonctionné

    répondre
    0
  • ringa_lee

    ringa_lee2017-04-22 09:01:30

    Le pare-feu de l'hôte est-il activé ? sudo service iptables status et voir.

    Exécutez sudo netstat -lnp | grep 3306 sur la machine hôte pour voir quel processus utilise le port 3306.

    répondre
    0
  • PHP中文网

    PHP中文网2017-04-22 09:01:30

    1

    <code>docker run --name djistore_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6.27 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci</code>

    Connectez-vous au service MySQL

    1

    <code>mysql -h 192.168.99.100 -u root -p</code>

    Journaux associés

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    <code>➜  ~ mysql -h 192.168.99.100 -u root -p

    Enter password:

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.6.27 MySQL Community Server (GPL)

     

    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

     

    Oracle is a registered trademark of Oracle Corporation and/or its

    affiliates. Other names may be trademarks of their respective

    owners.

     

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

     

    mysql> show databases;

    +--------------------+

    | Database           |

    +--------------------+

    | information_schema |

    | mysql              |

    | performance_schema |

    +--------------------+

    3 rows in set (0.01 sec)</code>

    répondre
    0
  • Annulerrépondre