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 127.0.0.1 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:
- [Solved] SQLSTATE[HY000] [2002] Connection refused to report an error when PHP connects to mysql in the docker container
- Docker: How to Solve MYSQL8 & Navicat remote connection error
- [Solved] Navicat connection error 1251 compatibility with docker MySQL
- Docker mysql8 modify password
- Remote connection to MySQL database error: is not allowed to connect to this MYSQL server solution
- IDEA maven Config MYSQL Connection Error: Could not create connection to database server.
- (Fixed) workbench MySQL Error Code: 2013. Lost connection to MySQL server during query
- C# Connect MYSQL Error: MySql.Data.MySqlClient.MySqlException:“SSL Connection error.”
- MySQL (version 8.0) connection error: 1251 [How to Solve]
- C# connection MySQL error: SSL connection error [Solved]
- [Solved] There is a problem with mysql8.0 without password in Navicat connection
- [Solved] MySQL connection error: communications link failure
- Sqlyog connection MySQL error: 2003 [How to Solve]
- [Solved] Centons7 docker:mysql:5.7 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
- [How to Solve] Docker-mysql-cron-backup cannot perform tasks
- [Solved] Error Code: 2013. Lost connection to MySQL server during query
- [Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)
- Android connection to cloud MySQL error: java.lang.NoClassDefFoundError Failed resolution of LjavasqlSQLType
- Mysql Flashback Warning: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe
- [Solved] Druid connection pooling Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The name you have to put there is the service name , not the container name.