Docker MYSQL '[2006] MySQL server has gone away'

六眼飞鱼酱① 提交于 2020-07-10 06:13:21

问题


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".

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


回答1:


Seems like you have a typo in mariadb service definition:

ports:
     - 3300:3306

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.

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...




回答2:


while it appears there is a typo for the port with this post I want to point out that it's important to make sure that your user has access 'TO' and 'FROM' the appropriate IP.

This is an (wide open -adjust as needed) example for updating the access domain when running adminer / phpadmin via docker:

GRANT ALL ON . TO 'admin'@'172.18.0.0/255.255.255.0' IDENTIFIED BY 'password' WITH GRANT OPTION;

p.s. I'm adding this answer here because I also landed on this page with the same error.



来源:https://stackoverflow.com/questions/57834108/docker-mysql-2006-mysql-server-has-gone-away

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!