Access denied when making connection from php container to mysql containerGet the solution ↓↓↓
I’ve been searching the web for hours but do not find any solution to my problem. I have 3 containers: - nginx - php - mysql
They are all connected to the same network.
If I try to log into mysql from the mysql container, all works fine. If I try to make a pdo connection from the php container to the mysql container, I always receive the message “Access denied for user”. I have no idea why. Let me show you guys what happens.
This is my docker-compose file:
If I go inside the danvers-php container and open a interactive shell for php and try to make a pdo connection I get this:
The connection is made as I see the incoming request in the log from danvers-mysql-app. What seems odd here is that the user-format in the error looks strange. I have no clue where the “danvers-php.projectdanvers_danvers” comes from. This is a concatenation of the php container and the network the containers are on. I think this is why the access is denied by have no clue how to change this as I assumed this should be the mysql containers name instead.
Does anybody have a clue to what I am doing wrong here?
Thanks for any reply or feedback.
In my mysql container I logged in with root and get this users list:
| user | host |
| d-app-conn-user | % |
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
The % for host name means no matter what the hostname is, as long as the username is correct, I should be able to login. The credentials are working from inside the mysql container but when the connection is made from another container, it fails. If I try to make a connection with SequelPro from my local machine through port 33061, it also works. The problem only exist when it's an inter container connection.
So I changed the nginx and php configuration with a php:7.4-apache configuration in my Dockerfile and now this problem does not exist anymore. I am able to log into the mysql container from the php container. The problem is related to the Nginx web server.
Share solution ↓
Link To Answer People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.