-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Cannot connect to mysql database: Access denied #51
Comments
The error usually means the password supplied is incorrect. |
The container is started with docker-compose. The yaml script is :
|
Have you changed the passwords since you first tried running the containers? docker-compose does extra work to preserve volumes between runs (thus preserving the database); you may want to try |
@yosifkit +1 I had the exact same issue and figured it out thanks to your answer. Is the -v flag even documented in the compose cli docs? I saw no mention of it on the rm command. |
Glad I could help. It doesn't seem to have anything (https://docs.docker.com/compose/cli/#rm). I think I verified it with |
I have to +1 here. I had my MySQL files in a data volume container that had stuck around and this discussion helped me realize it. |
This got me as well, opened an issue. Thanks @yosifkit! |
@yosifkit thank you so much for your advice, you saved me ❤️ |
@yosifkit Thanks again... However, another detail here is that if you use a data container with docker-compose, you need to delete the ENTIRE directory before running again.
The command
At this point, the only way to make it right is to delete the directory that you mapped your mysql data.
Only after that, the command created a new database with the users correctly set! Good luck! |
You are correct; |
I had the same error but from a different cause: |
Note also that if you have a non-named volume (e.g. something like below in your In ...
volumes:
data_volume: If you run |
I have to give a + 1 on this discussion because I had different passwords going on for 2 containers trying to connect to mysql with Thanks |
yes @marcellodesales you're a star! thank you!! |
Another possible resolution to the 'access denied' issue is provided in this issue: #241. |
I was facing this issue, not related to Docker, but found it while using docker-compose with multiple mysql instances on localhost:
I am using OSX, so all my connections using |
We ran into this issue because we used the env var |
I just still got this error even I use |
@Rukeith, |
@yosifkit I didn't mount any volume |
I had similar problem apparently some characters aren't allowed in the password.. after changing the password environment variable and removing the volume the issue was resolved |
I had this problem, too. |
@taha-moghaddam I solved it with this command. Thank you 👍 |
I didn't see it coming! |
Hello, clearing the data volumes made by app to connect to mysql using docker-compose. |
in my case it was a permission issue to the mounted volume. |
Acctually, the command that resolved for me was |
I have a similar problem(changing |
Thank you |
Thanks @sfmok this worked for me. Also as thank you @amir5121 as you stated some characters are not accepted and I found this to be spot on with an error I was receiving, so I decided to go with a basic password. In addition to removing the data directory I used the "docker volume prune" command to remove all volumes associated on the host machine. Thank you again guys! |
You save my life!!! 🥺 |
You saved my life |
I ran into the same problem a few minutes ago. Keep in mind that there must not be a space after the "-p" argument. |
Man, u're the best, u saved my life !! |
I my case, I had to execute all these steps to solve this problem:
|
faced same issue.Seems the problem is with volumes with originally created when there is no mysql_root_password was defined in docker-compose.yaml file.After removed using docker volume rm(since named volumes not removed while running docker-compose rm -v) and reran docker-compose up after updated yaml file with mysql_root_password,it was working properly |
|
I got the access denied error because I had a dollar sign in my password, which the docker compose file parses as variable substitution (I've only seen the ${} syntax) on this page you will read "Both Therefore if I had for example this as my database password in the docker compose file: hello$world, the world variable would get substituted, of course I don't have a 'world' variable, the password that would be set in that case would be 'hello', so without knowing the docker compose syntax you would be trying to log in with 'hello$world', and you'd be denied access. |
This command solved my problem, thank you very much. |
It makes so much sense now !!! |
Thank you! This saved me. |
docker system prune helped me |
And I ran |
docker-compose rm -v did not work for me. This only worked for me. |
OS: MacOS Catalina 10.15.3
I wen't inside the mysql container to login
I did |
@iryanjan18, you need to remove the quotes in your yaml, switch to a map (instead of a list), or use them in your password to mysql. # either of these should work
environment:
- MYSQL_ROOT_PASSWORD=passwd
environment:
MYSQL_ROOT_PASSWORD: "passwd"
|
|
I had same issue with a running mysql instance in a docker container. |
Wish I could get you a beer! Thank you!!! |
It seems it works differently with WSL 2, has anyone tried? |
Worked for me thanks, saved me a lot of time. |
My case was trivial, but I spent a lot of time searching for an answer, including carefully reading through this thread, so it might be helpful for someone in the future. In my case, I was starting a container with Then I tried to start it without It turned out, my user was not created because username was 1 character too long, and I got |
Make sure you has the next config, remove the volume and try again...
Of course, the empty password is only to make easy the management for the development environment. |
Unfortunately, I tried all of the solutions above and none worked for me. This is the docker-compose file I have: version: "3.7" db: nginx: networks: |
These sorts of questions/requests for support would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. |
I have issues connecting to the mysql database spawned by this docker container. I ger repeated access denied errors. I tried multiple ways:
nsenter --target $(docker inspect --format {{.State.Pid}} etc_mysql_1) --mount --uts --ipc --net --pid /bin/bash
run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
I tried with and without a password. With the root user and with
$MYSQL_USER
. With the-h localhost
or-h mysql
or without. Each time, I get an error similar to this:This is the environment of the mysqld process:
Do you have an idea why it fails?
Thank you
The text was updated successfully, but these errors were encountered: