使用mariadb容器的locahost上的MySQL连接失败

时间:2018-05-17 09:36:40

标签: docker mariadb

问题

我无法从运行MariaDB容器的主机连接MySQL。以下是一些有关环境的信息:

docker compose - 文件

version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    environment:
      BIND-ADDRESS: 0.0.0.0
      MYSQL_ROOT_PASSWORD: example
    ports:
      - 3306:3006
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

通过docker exec -it rancherclientplatform_db_1 /bin/bash与容器连接以及与mysql -uroot -p的连接无疑令人惊讶。

奖励

拨款如下:

MariaDB [(none)]> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              
|
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*57237BB49761F29AB9724BA084E811D70C12393D' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                                                          
|
+----------------------------------------------------------------------------------------------------------------------------------------+

在主机上

当我尝试连接主机时没有

  • mysql -uroot -p
  • mysql -hlocalhost -uroot -p
  • mysql -h127.0.0.1 -uroot -p

的工作。前2个因套接字错误而失败,-h127.0.0.1失败 ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"

端口3306本身似乎正确地发布到主机,如 nmap -p3306 localhost发送

PORT     STATE SERVICE
3306/tcp open  mysql

关于该怎么做的任何想法?

1 个答案:

答案 0 :(得分:1)

MariaDB默认端口是3306.

所以:

  

端口:          - 3306:3006

如果您想使用端口3306访问localhost上的mariadb,您可能希望使用3306:3306映射端口