• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Fix WordPress Error in Database Connection : MySQL Part

By Abhishek Ghosh October 27, 2015 8:49 am Updated on October 27, 2015

Fix WordPress Error in Database Connection : MySQL Part

Advertisement

MySQL Setup & Corrupted Database Has to Do With the Error Establishing a Database Connection. All know – restarting MySQL from SSH fixes the issue instantly in majority of the cases! We Will Fix WordPress Error in Database Connection in this Guide Alongwith Basic Error Log Analysis. For whom this article is intended? Advanced users or who are learning to become advanced users. This guide is for dedicated server, cloud server instance, traditional VPS etc. but not for Shared Hosting. It is meaningless to pay $15/month for a Shared Hosting when at $10/month one can get one 01 GB cloud server instance.

We expect that, the user is using Percona or MySQL or MariaDB and know how to do SSH!

Error Establishing a Database Connection is more common in DigitalOcean, Linode etc. over HP Cloud, Rackspace Cloud with everything being the same. We do not know the reason. We guess, these are related to network card or router working behind – minor issue get magnified. Rackspace Cloud cost huge for the tuning works at backend!

Advertisement

---

 

Fix WordPress Error in Database Connection : MySQL Part

 

WordPress database is quite pathetic in real life. If you have ever used Apache2 (you means your database) and now using Nginx, there is enough chance of getting Error Establishing a Database Connection message. First divine work is to eliminate the chance of corrupted database, it may not be so easy as we wrote here – Fix Sudden Error Establishing a Database Connection.

Above hyperlinked way is an easy method, just add :

Vim
1
define('WP_ALLOW_REPAIR', true);

in /wp-config.php file and visit https://this_is_your_site.com/wp-admin/maint/repair.php on browser and follow the web instruction. Automatic system. Wait! Read ahead. Yes, very risky without a database backup. Easy to take a backup from SSH :

Vim
1
mysqldump -h localhost -u root -p you_wp_db_name > wpbackup.sql

I will suggest to create a database beforehand :

Vim
1
2
3
CREATE DATABASE backupwp;
use backupwp;
\. wpbackup.sql

With that last line, from dump, database will be created. Few minutes matter. So, your backup database username is root with your password, database name is backupwp. Live working backup of database. Now run that database repair of WordPress. If sky breaks on the head, change credential in /wp-config.php file to that backup’s one. Simple.

Fix WordPress Error in Database Connection - MySQL Part

 

Fix WordPress Error in Database Connection : mysql_safe is Idiot

 

mysqld is odd. Run mysqld --verbose --help in SSH screen. MySQL should never die in that way throwing an abnormal error. MySQL Safe actually kept as failsafe way to not die :

Vim
1
https://dev.mysql.com/doc/mysql-startstop-excerpt/5.5/en/mysqld-safe.html

Basically, by default, at my.cnf under [mysqld_safe], all needed are not present, socket, PID if not present, probably mysqld can not restart on crash (I am not MySQL database expert) :

Vim
1
2
3
4
5
6
[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
log_error=/var/log/mysqld.log
datadir=/var/lib/mysql

In real life – you really never need an external script to restart MySQL. Yeah, the above thing kill keep MySQL server up but, it may still die at some action when you’ll perform. It is unlikely to fail to restart on a well tuned my.cnf.

 

Fix WordPress Error in Database Connection : Never Use Script, Software to Restart MySQL on Failure

 

People uses monit to auto restart MySQL on failure but without reading software engineering, I can definitely say – that Indian bloggers promoted monit to auto restart MySQL on failure is wrong approach. MySQL is very powerful software. Upon any sort of attack on MySQL, it is better if gets shut down. Do not do idiotic works. Log files are not for decoration. This is a very basic log analysis followed by fix. Our servers never need such “auto restart mysql on crush script”? Billions of WordPress are running on this Earth without such idiotic methods. If some error of MySQL can not be fixed by you, you need a good MySQL expert. Do not find a cheap Indian “MySQL Expert”. Good person around MySQL will charge the same all around the World.

Tap that /var/log/mysqld.log :

Vim
1
cat /var/log/mysqld.log

Here is an example of error with huge output.

In the log, there is clear history of crushes :

Vim
1
2
2015-10-27 08:10:16 7841 [Note] Starting crash recovery...
2015-10-27 08:10:16 7841 [Note] Crash recovery finished.

As you can see, for that database, there are errors which are clearly possible to fix. WordPress database need fix :

Vim
1
Unsafe statement written to the binary log using statement format since BINLOG_FORMAT

Another one in combination :

Vim
1
Too many connections

Everyone knows to fix – run locate my.cnf and find the path of my.cnf and open that with a text editor :

Vim
1
nano /etc/mysql/my.cnf

search for max_connections and increase the value. Gracefully restart mysql (service mysql restart for Ubuntu). If you get :

Vim
1
2
* Stopping MySQL (Percona Server) mysqld                                [ OK ]
* Starting MySQL (Percona Server) database server mysqld                [fail]

that means, max_connections value was edited to too high. Lower it & gracefully restart mysql. After solving all the problems, empty the log file :

Vim
1
echo " " > /var/log/mysqld.log

Tagged With error establishing a database connection digitalocean , mariadb regular Error establishing a database connection

This Article Has Been Shared 271 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Fix WordPress Error in Database Connection : MySQL Part

  • Adding Schema.org Structured Data in Genesis Theme

    Adding Schema.org Structured Data in Genesis Theme without using any plugin is quite easy as Genesis has great documentation and has excellent existing markups.

  • WordPress Post to Downloadable PDF, Text : Practical Options

    WordPress Post to downloadable PDF, Text has many points to consider when we will think about the usability, SEO, HTML5 and Schema.org markups.

  • Remove WordPress Plugin From Database Video Guide

    Remove WordPress Plugin From Database Video Guide shows how to delete tables, rows from MySQL database for plugins previously installed and uninstalled later.

  • Outgoing Link Tracking with Google Analytics

    Outgoing Link Tracking with Google Analytics is quite easy to setup both with the traditional or the asynchronous code. You can track outgoing certain link.

  • Remove wp-emoji-release.min.js Loading From WordPress

    This new javascript of emoji is added in WordPress 4.2 which force loading wp-emoji-release.min.js at front end. Here is how to easily remove.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (20K Followers)
  • Twitter (4.9k Followers)
  • Facebook (5.8k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.2k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Top 10 Anti Hacking Software for Microsoft Windows January 22, 2021
  • What is Software Modernization? January 21, 2021
  • Cloud Computing : Cybersecurity Tips for Small Business Owners January 20, 2021
  • Arduino : Independently Blink Multiple LED January 18, 2021
  • What is a Loosely Coupled System? January 17, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Fix WordPress Error in Database Connection : MySQL Part," in The Customize Windows, October 27, 2015, January 22, 2021, https://thecustomizewindows.com/2015/10/fix-wordpress-error-in-database-connection-mysql-part/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy