Docker MYSQL'[2006] MySQL服务器不见了“ [英] Docker MYSQL '[2006] MySQL server has gone away'

查看:111
本文介绍了Docker MYSQL'[2006] MySQL服务器不见了“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对mysql服务器有一点问题。
i创建了我的docker-compose.yml,但是当我想访问phpMyAdmin(localhost:8080)时,出现一条错误消息,说:
phpMyAdmin试图连接到MySQL服务器,并且该服务器拒绝连接。请检查配置中的主机,用户名和密码的值,并确保它们与MySQL服务器管理员提供的信息匹配。

i have a little problem with mysql server. i created my docker-compose.yml, but when i want to access to phpMyAdmin (localhost:8080), an error message appeared sais that: "phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. Please check the values ​​of host, username and password in the configuration and make sure they match the information provided by the MySQL server administrator".

此处是我的docker-compose文件,感谢您的帮助

Here is my docker-compose file and thanks for helping me

version: '2'
services:
  apache:
    image: rafaelcgstz/magento2
    # build: .
    ports:
      - 80:80
      - 9001:9000
      # - "35729:35729" # live reload
    volumes:
      - ./src:/var/www/html
      - ~/.composer:/var/www/.composer
      - ~/.npm:/var/www/.npm
      # - ~/.nvm:/var/www/.nvm
    environment:
      XDEBUG_CONFIG: "remote_host=localhost"
      PHP_IDE_CONFIG: "serverName=Docker"
    depends_on:
      - db
    links:
      - db
    networks:
      - magento-network

  db:
    image: mariadb
    ports:
     - 3300:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=magento
      - MYSQL_PASSWORD=magento
    volumes:
      - dbdata:/var/lib/mysql
    networks:
      - magento-network

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
     - PMA_HOST=db
     - PMA_USER=root
     - PMA_PASSWORD=root
     - MYSQL_ROOT_PASSWORD=root
    ports:
     - 8080:80
    networks:
      - magento-network

  redis:
    image: redis
    ports:
     - 6379
    networks:
      - magento-network

  redis-session:
    image: redis
    ports:
     - 6379
    networks:
      - magento-network

  mailhog:
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025
    networks:
      - magento-network

networks:
  magento-network:
    driver: bridge

volumes:
  dbdata:
    driver: local


推荐答案

似乎您在 mariadb 服务定义中有错字:

Seems like you have a typo in mariadb service definition:

ports:
     - 3300:3306

您配置了端口映射,以便可以在 3300 到达容器,但您没有将此信息传递给PHPMyadmin。因此,连接尝试只会超时。

You configured port mapping so that container is reachable at 3300 but you did not pass this information to PHPMyadmin. As a result connection attempt just times out.

侧面说明:您根本不需要公开数据库的端口-其他容器将使用Docker的虚拟网络与之通信,并且对于本地访问,您可以使用 docker container -it exec< container-id> mysql ... docker-compose exec db mysql ...

Side note: you do not need to expose port for database at all - other containers will communicate with it using Docker's virtual network and for local access you can use docker container -it exec <container-id> mysql... or docker-compose exec db mysql...

这篇关于Docker MYSQL'[2006] MySQL服务器不见了“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆