The configuration below works just fine on my local machine:
My docker-compose.yml
file:
networks:
mynet:
name: mynet
driver: bridge
services:
mydb:
container_name: mydb
image: mysql:8.4.2
hostname: mydb
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${ROOT_PASSWORD}
MYSQL_DATABASE: default_db
networks:
- mynet
volumes:
- ${DATA_VOLUME}:/var/lib/mysql
ports:
- ${EXPOSE_PORT}:3306
myadmin:
container_name: myadmin
image: phpmyadmin/phpmyadmin:5.2.1
hostname: myadmin
depends_on:
- mydb
restart: unless-stopped
environment:
PMA_HOST: mydb
# PMA_PORT: 3306 - I tried with this parameter too
# PMA_ARBITRARY: 1 - I tried with this parameter too
# MYSQL_USERNAME: "root" - I tried with this parameter too
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
networks:
- mynet
ports:
- ${PMA_EXPOSE_PORT}:80
And here is the .env
file:
ROOT_PASSWORD=mystrongpwd
DATA_VOLUME=/path/to/my/colume
EXPOSE_PORT=3333
PMA_EXPOSE_PORT=4444
But when I'm trying to login to myadmin, I get this error:
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'172.26.0.12' (using password: YES)
UPDATE: So, there is a question here:Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user which causes this question to get closed by the users. but that is not the answer. I found the answer and I post it below.
I changed these to things and all works fine:
# in environment section:
environment:
MYSQL_ROOT_HOST: '%'
# the rest of envs
# also I had to add this command:
command: ["mysqld", "--mysql-native-password=ON"]
I'm using mysql:8.4.2
and it seems to enabling password login with root
just needs the ["mysqld", "--mysql-native-password=ON"]
command.
Also, it's pretty new to me, but login from another container was not allowed unless I added the MYSQL_ROOT_HOST: '%'
part.