Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress database error MySQL server has gone away for query

I get this error so frequently that the php_error log file increases 1MB every 2 seconds. and the site is very slow.

I have tried to add this line to wp-db.php

$this->query("set session wait_timeout=600" );

but it did not help.

The web server is IIS 7, latest version of mysql and wordpress

like image 773
Mario Avatar asked Mar 28 '13 23:03

Mario


People also ask

What causes MySQL server has gone away?

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. In this case, you normally get one of the following error codes (which one you get is operating system-dependent). The client couldn't send a question to the server.

How do I fix the lost connection to MySQL server during query?

Open the MySQL Workbench Preferences. Check if the SSH Timeout and DBMS Timeout value is set to only a few seconds. Try to increase the default value of the connection timeouts. Save the settings, close the MySQL Workbench and reopen the connection to see if you are able to connect to the database.

Why MySQL database is not connecting?

Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.


2 Answers

This trick will work for all WordPress versions. Open your Wordpress directory. The directory will contain the folders :

wp-admin
wp-content
wp-includes

Open wp-includes. Search for the wp-db.php file. If you found the file, open it using a text editor. Using the text editor's search tool, search for :

$this->ready = true;

Once you found the line, add the following lines just after the found line :

//WP Query Gone Away Error Fix
$this->query("set session wait_timeout=600");

You can also follow https://subinsb.com/fix-wordpress-error-mysql-server-has-gone-away link to view in more detials.

like image 138
Paras Avatar answered Sep 29 '22 00:09

Paras


Run SHOW STATUS WHERE Variable_name LIKE '%onn%' to see how many open connections you have. Mine looks like this:

Variable_name        Value
Aborted_connects         1
Connections            629
Max_used_connections     3
Ssl_client_connects      0
Ssl_connect_renegotiates 0
Ssl_finished_connects    0
Threads_connected        2

Run SHOW PROCESSLIST to see what processes are active.

The problem may be that you are opening too many connections and not closing them. Running these commands will at least give insight into what may be the issue.

like image 38
Joe Frambach Avatar answered Sep 28 '22 23:09

Joe Frambach