Skip to main content

MySQL server has gone away



MySQL server has gone away for query


MySQL server has gone away for query 

[Picture 6.  pic/mta-ube.png]


Solution for “WordPress database error MySQL server has gone away for query…”

If you have a WordPress blog and it is hosted on a shared server then you may want to continue reading..
For the past six months or so, my blog has been doing weird things.. like timing out, taking ages to load pages, sometimes the login page wouldn’t appear for me, etc..
Just random events occurring now and then.. or so I thought.
Also my CPU utilisation was going through the roof, resulting in warnings from my web host to reduce it, or else risk my site going offline.
So I decided to dig a bit deeper to try to find out the root cause of these issues.

Error Log

After logging into my website one day I noticed an error_log in the /public/html directory,
So I opened it up to see what it contained,
I was quite shocked when I discovered the following error,
WordPress database error MySQL server has gone away for query…” was appearing multiple times a day, every single day..

Why This Error Appears

After digging around using Google, I eventually found this brilliant article at Rob’s Notebook called “Workaround for WordPress database error: [MySQL server has gone away] for different versions of WordPress” that provides the workaround for this error.
Rob goes on to explain why this error appears,
“When someone tries to view one of your WordPress web pages, the PHP code first opens a connection to the MySQL server. Subsequent queries to the MySQL server rely on the connection remaining open, and do not re-open the connection. If the connection to the server happened to have shut down before a query is made, then WordPress will display this error.”

Solution

Rob’s solution is to change the “wait_timeout” variable to 600 in the wp-db.php file which is located in the\wp-includes directory,
Open up this file using a text editor.. and do a search for the following text (this will bring you to the general area that needs to be edited),
  • !$this->dbh
Now copy the following,
  • $this->query("set session wait_timeout=600");
The place to insert this line is,
  1. Inside the “__construct(…)” function – see below in green
  2. And after the closing brace ‘}’ of the “if (!$this->dbh) {” statement – see below in blue
  3. Paste in $this->query("set session wait_timeout=600"); – see below in red

Now <Save> this newly modified wp-db.php file.
Done!
Since adding this, the “WordPress database error MySQL server has gone away for query…” no longer appears in my error_log..
My blog has now become more stable, more efficient and more responsive.

Future WordPress Upgrades

You will need to do this each time you upgrade WordPress.. a real pain.. but necessary to keep this error from appearing.
Full credit goes to Rob for discovering this solution!
Enjoy!





FEED






Share










SUPPORT
















VISIT COUNTER !!








ROHIT PATEL
 



Comments

Popular posts from this blog

Hacking via Cloning Site Using Kali Linux

Hacking via Cloning Site Using Kali Linux Hacking via Cloning Site Using Kali Linux  SET Attack Method : SET stands for Social Engineering Toolkist , primarily written by  David Kennedy . The Social-Engineer Toolkit (SET) is specifically designed to perform advanced attacks against the human element. SET was designed to be released with the  http://www.social-engineer.org  launch and has quickly became a standard tool in a penetration testers arsenal. The attacks built into the toolkit are designed to be targeted and focused attacks against a person or organization used during a penetration test. Actually this hacking method will works perfectly with DNS spoofing or Man in the Middle Attack method. Here in this tutorial I’m only writing how-to and step-by-step to perform the basic attack , but for the rest you can modified it with your own imagination. In this tutorial we will see how this attack methods can owned your com...

Defacing Sites via HTML Injections (XSS)

Defacing Sites via HTML Injections Defacing Sites via HTML Injections What Is HTML Injection: "HTML Injection" is called as the Virtual Defacement Technique and also known as the "XSS" Cross Site Scripting. It is a very common vulnerability found when searched for most of the domains. This kind of a Vulnerability allows an "Attacker" to Inject some code into the applications affected in order to bypass access to the "Website" or to Infect any particular Page in that "Website". HTML injections = Cross Site Scripting, It is a Security Vulnerability in most of the sites, that allows an Attacker to Inject HTML Code into the Web Pages that are viewed by other users. XSS Attacks are essentially code injection attacks into the various interpreters in the browser. These attacks can be carried out using HTML, JavaScript, VBScript, ActiveX, Flash and other clinet side Languages. Well crafted Malicious Code can even hep the ...

Hacking DNN Based Web Sites

Hacking DNN Based Web Sites Hacking DNN Based Web Sites Hacking DNN (Dot Net Nuke) CMS based websites is based on the Security Loop Hole in the CMS. For using that exploit we will see the few mentioned points which illustrates us on how to hack any live site based on Dot Net Nuke CMS. Vulnerability : This is the know Vulnerability in Dot Net Nuke (DNN) CMS. This allows aone user to Upload a File/Shell Remotely to hack that Site which is running on Dot Net Nuke CMS. The Link's for more Information regarding this Vulnerability is mentioned below -                                  http://www.exploit-db.com/exploits/12700/ Getting Started : Here we will use the Google Dork to trace the sites that are using DNN (Dot Net Nuke) CMS and are vulnerable to Remote File Upload. How To Do It : Here, I an mentioning the few points on how to Search for the existing Vulnerability in DNN. Let'...

Excellent tricks and techniques of Google Hacks

Frontpage.. very nice clean search results listing !! I magine with me that you can steal or know the password of any web site designed by "Frontpage". But the file containing the password might be encrypted; to decrypt the file download the program " john the ripper". To see results; just write in the ( http://www.google.com/ ) search engine the code: "# -FrontPage-" inurl:service.pwd ============================================== This searches the password for "Website Access Analyzer", a Japanese software that creates webstatistics. To see results; just write in the ( http://www.google.com/ ) search engine the code: "AutoCreate=TRUE password=*" ============================================== This is a query to get inline passwords from search engines (not just Google), you must type in the query followed with the the domain name without the .com or .net. To see results; just write in the ( http://www.google.co...

Hacking via BackTrack using SET Attack Method

Hacking via BackTrack using SET Attack Method Hacking via BackTrack using SET Attack  1. Click on Applications, BackTrack, Exploit Tools, Social Engineering Tools, Social Engineering Toolkit then select set.