GoDaddy Error: PHP “Lost Connection to MySQL Server During Query” — How To Fix
While on a GoDaddy Shared Hosting plan, I got this error:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query
The site was previously working fine but suddenly stopped working. Below is how I resolved it.
More Details About The Problem
The “real” site was in the format of sample-app.com/clients/novigrad
I had a subdomain in the format of novigrad.sample-app.com to display it.
Everything was working fine.
The site loaded up locally. In my local environment, I was connecting to the remote GoDaddy MySQL database.
Make sure the “Remote MySQL” has the necessary IP address(es) in the cPanel
In the FTP, the file error_log appeared. Viewing it, I could see the problem listed above.
A Possible Cause
Note: this is pure speculation!
I had to delete an image on the FTP. After doing this, that’s when everything broke. I thought there was some sort of caching issue with the GoDaddy subdomain-to-subdirectory.
Other content (ex HTML) loaded up — but the page stopped loading after the MySQL error.
One Solution That Didn’t Work
I created an additional subdomain, pointing to the same subdirectory, i.e. :
novigrad2.sample-app.com also went to the existing subdirectory of sample-app.com/clients/novigrad
That didn’t work.
I went to the “real” URL of sample-app.com/clients/novigrad/endPoint.php which also did not load up. All giving the same error.
I narrowed it down to the GoDaddy “web” server not being able to connect to the “database” server. Again, I was able to connect to the remote database server from my local computer.
How I Fixed It
- I uploaded everything to a new subdirectory on the FTP
- I created a new subdomain and linked it to that new directory
- I confirmed everything was working!
- I deleted the original subdomain
- I recreated the original subdomain pointing to the new directory
My diagnosis was that the remote subdirectory on GoDaddy became corrupt, which happened when I deleted an image. Creating a new subdirectory fixed it!
Not to stuff this post with keywords, but hopefully if you Google for GoDaddy PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query then this will help 😃