Mysql: Docker Compose mysql MYSQL_ROOT_PASSWORD not work

Created on 21 Jun 2016  路  14Comments  路  Source: docker-library/mysql

here is my config file:

mysql:
  image: mysql:latest
  environment:
    - MYSQL_ROOT_PASSWORD=test
    - MYSQL_DATABASE=test

I start docker, when i try to connect mysql using test as password, failed.
the password is still root

Most helpful comment

Some workarounds:

Remove all unused volumes

docker volume prune

Remove one or more volumes

To remove the volume from your db service

docker volume rm <database_data>

Docker compose Down containers e remove volumes

docker-compose down --volumes

All 14 comments

Are you mapping to an existing database or creating a new one?
The root password variable will only be used when creating a database. It won't change the root password of an existing one.

@ltangvald hi, i just wanna set the root password when start docker, but it not work

@ltangvald MYSQL_DATABASE=test didn't create a database named test

Creation of databases also only happens in there's no existing datadir. Did you map a volume containing an existing MySQL database when starting up the container?

no

sorry, my bad, i know the reason, justrmthe container and restart, everything ok, thank you @ltangvald

@iawia002 i am also having same problem, i tried with your solution is not for me.
can you please tell me the what exact error for this.
now i am using the latest MYSQL 8.0.13.

@bhaskar423 Could you describe exactly what you're doing and what happens?

Sure, acutely i took the image from the public docker hub 8.0.13 image and i want to give the MYSQL password while up the container with environment variable,
environment:
- MYSQL_ROOT_PASSWORD=test
i gave the ENV like above, and if i inspect the container i can see my password as "test" and if try to login into mysql server authentication fail error getting.
default password : PASSWORD is working.

Same here, with mariadb:latest image. I already mapped /var/lib/mysql externally, but whatever I do, it does not seem to pickup on the environment set password for root.

@jult one thing I have noticed is that the root user is created but only allowed to login from localhost so you can't log in from anything other than by connecting via the shell.

Important to note that the image entrypoint script will never make changes to an existing database.
If you mount an existing data directory into var/lib/mysql, options like MYSQL_ROOT_PASSWORD will have no effect

same issue, thanks to @ltangvald ,his answer work well for me

Some workarounds:

Remove all unused volumes

docker volume prune

Remove one or more volumes

To remove the volume from your db service

docker volume rm <database_data>

Docker compose Down containers e remove volumes

docker-compose down --volumes
Was this page helpful?
0 / 5 - 0 ratings