Docker : MySQL password is not set despite setting environement variable (-e MYSQL_ROOT_PASSWORD)

Viewed 336

I dockerize a MySQL db with this code : docker run --name db -e MYSQL_ROOT_PASSWORD=root -v $HOME/mysql-data:/var/lib/mysql -d mysql:5.7 which is supposed to create a password : root, BUT when I try to connect to database while entering that password, I get denied access. I can only access to DB if I log without entering any password (only if I leave the password blank). What am I doing wrong or what did I misunderstand ?

PS: I tried to change the password to something else but root and got same result.

1 Answers

From the documentation on the official MySQL Docker image (https://hub.docker.com/_/mysql):

If you start your mysql container instance with a data directory that already contains a database (specifically, a mysql subdirectory), the $MYSQL_ROOT_PASSWORD variable should be omitted from the run command line; it will in any case be ignored, and the pre-existing database will not be changed in any way.

Related