Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Compose mysql MYSQL_ROOT_PASSWORD not work #180

Closed
iawia002 opened this issue Jun 21, 2016 · 18 comments
Closed

Docker Compose mysql MYSQL_ROOT_PASSWORD not work #180

iawia002 opened this issue Jun 21, 2016 · 18 comments

Comments

@iawia002
Copy link

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

@ltangvald
Copy link
Collaborator

ltangvald commented Jun 21, 2016

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.

@iawia002
Copy link
Author

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

@iawia002
Copy link
Author

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

@ltangvald
Copy link
Collaborator

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?

@iawia002
Copy link
Author

no

@iawia002
Copy link
Author

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

@bhaskar423
Copy link

@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.

@ltangvald
Copy link
Collaborator

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

@bhaskar423
Copy link

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.

@jult
Copy link

jult commented Jan 28, 2019

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.

@SJrX
Copy link

SJrX commented Feb 25, 2019

@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.

@ltangvald
Copy link
Collaborator

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

@pythonzm
Copy link

pythonzm commented Apr 4, 2019

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

@RCristiano
Copy link

RCristiano commented Oct 11, 2019

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

@gh0sthx
Copy link

gh0sthx commented May 14, 2021

I mapping to an existing database. Does this mean that my MYSQL_PASSWORD and MYSQL_USER are not working ?

@RCristiano
Copy link

@Paladinhanxiao
Yes, or it would be a big security problem

@kingma-sbw
Copy link

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

Removing a volume potentially means removing all images and hence containers or not? That would be hardly a solution

@tianon
Copy link
Member

tianon commented Apr 3, 2023

Removing the volume means removing all your stored data - images and containers are separate from that.

Unfortunately, we do not have the bandwidth to provide in-depth integration/deployment/environment debugging or support here; these sorts of questions/requests would be more appropriately posted to a dedicated support forum, such as the Docker Community Slack, Server Fault, Unix & Linux, or Stack Overflow.

@docker-library docker-library locked as resolved and limited conversation to collaborators Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants