Home > Back-end >  Phpmyadmin and mysql connection fails after docker-compose down and up again
Phpmyadmin and mysql connection fails after docker-compose down and up again

Time:03-08

This is my docker-compose.yml file to launch PMA and mysql:

version: '3.8'
services:
 
  mysql_db:
    image: mysql:8.0.28
    ports:
      - "64121:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=rootsecretpassword
      - MYSQL_DATABASE=dbname
      - MYSQL_USER=db-username
      - MYSQL_PASSWORD=db-password
    volumes:
      - mysql_data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5.1.2
    ports:
      - "64122:80"
    environment:
      - MAX_EXECUTION_TIME=600 
      - UPLOAD_LIMIT=800M
      - PMA_HOST=mysql_db
      - PMA_PORT=3306
      - PMA_ARBITRARY=1
    depends_on:
      - mysql_db


volumes:
  mysql_data:

docker-compose up --build

Then, I can reach localhost:64122 to see PMA(phpmyadmin) and I can login using credentials and everything works fine, But after running docker-compose down and docker-compose up --build I can't login to PMA and it says:

 Cannot log in to the MySQL server
 mysqli::real_connect(): (HY000/1130): Host 'SOME IP ADRESS' is not allowed to connect to this MySQL server

So, what happens during down and up in docker that makes this error?

CodePudding user response:

Database user can connect only from localhost by default

SELECT host FROM mysql.user WHERE user = "db-username";

Update user table:

GRANT ALL ON dbname.* to 'db-username'@'%' IDENTIFIED BY 'db-password';
FLUSH PRIVILEGES;
SELECT host FROM mysql.user WHERE user = "db-username";
  • Related