DEV Community

Kiran Krishnan
Kiran Krishnan

Posted on • Updated on • Originally published at kirandev.com

MySQL + phpMyAdmin Docker Compose

Here is a simple docker-compose file to run MySQL + phpMyAdmin services for your development needs.

Create a file docker-compose.yml.

Copy and paste the below code.

Run it using the command docker-compose up.

version: "3"

services:
  # Database
  db:
    platform: linux/x86_64
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: yourdb
      MYSQL_PASSWORD: password
    networks:
      - mysql-phpmyadmin

  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin
    restart: always
    ports:
      - "8090:80"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
    networks:
      - mysql-phpmyadmin

networks:
  mysql-phpmyadmin:

volumes:
  db_data:
Enter fullscreen mode Exit fullscreen mode

You can access the phpMyAdmin at http://localhost:8090/

Top comments (4)

Collapse
 
charlesderek profile image
CharlesDerek

Returns:
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'{LocalHostIpAddress}' (using password: YES)

Same thing happens with any other user made.

Collapse
 
hungdev profile image
Hung Vu • Edited

First step login root/your-mysql-password in your local phpmyadmin
it returns:
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'{LocalHostIpAddress}' (using password: YES)

docker exec -it <container_name_mysql> mysql -u root -p
( you can get from: docker ps)
it will ask password of MYSQL_ROOT_PASSWORD

after accessing mysql, run command:
CREATE USER 'root'@'192.168.0.4' IDENTIFIED BY 'password';

(192.168.0.4 is LocalHostIpAddress, replace it)

run command:

FLUSH PRIVILEGES;

done!
login with root/your-mysql-password again!

Collapse
 
rmontero profile image
Rafael Montero

I know this is an old post. But thanks it worked for me as well

Collapse
 
cavein254 profile image
John Muthua

@hungdev, 🔥 🔥 This worked for me. I think the author should just include it in the tutorial