Tag Archives: SQLSTATE[HY000] [2002] Connection timed out

MySQL connection timeout: error sqlstate [HY000] [2002] connection timed out

Why can’t you grab tickets when you travel on holiday?Reveal the key technology of 12306 how to ensure the ticket is not oversold>>>

I found a lot of them on the Internet, but they were all wrong

Later, I realized that it was actually a matter of setting

When your code is deployed to the server, the host value of your MySQL should be

127.0.0.1

Not your server IP

Otherwise, it will report an error

In fact, when your code enters the server, MySQL and the code are under the same IP, so 127.0.0.1 should be used instead of the server IP

Remember! No need to change the configuration