[Solved] docker mysql SQLSTATE[HY000] [2002] Connection refused

Use docker to build the lnmp environment, and use a sub-container construction scheme. The
framework uses thinkphp and wants to connect to the data MySQL. It always shows “SQLSTATE[HY000] [2002] Connection refused”. The
database configuration host is filled with localhost, and then changed to 127.0 .0.1, I can’t connect.
I thought it was a database user permission problem. I created a new user and refreshed the permissions. The result was still not working for
a long time. It turned out to be a problem of sub-containers. If you connect to or localhost in the container, you must not be able to connect to the database MySQL. You
should fill in the database configuration host with the name of the MySQL container. My local MySQL container name is MySQL, so you can connect to it.

Read More:

1 thought on “[Solved] docker mysql SQLSTATE[HY000] [2002] Connection refused

Leave a Reply

Your email address will not be published. Required fields are marked *