• 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
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, 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

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Join/Merge Multiple Log Files For Big Data Analysis

    Here Are The Ways To Join/Merge Multiple Log Files For Big Data Analysis, Store Them To OpenStack Based Cloud Storage And Delete Old Files.

  • Steps to Install Percona MySQL Server on Ubuntu 18.04 LTS

    Here is Latest, Tested Steps to Install Percona MySQL Server on Ubuntu 18.04 LTS For Cloud Server, VPS and Dedicated Server.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

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

Get new posts by email:

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 (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Affordable Earphone/IEM for Audiophiles: HiFiMan RE-400 WaterlineOctober 2, 2023
  • What is Hardware Security Module (HSM)September 30, 2023
  • Transducer Technologies of HeadphonesSeptember 28, 2023
  • What is Analog-to-Digital Converter (ADC)September 27, 2023
  • Comparison of Tube Amplifiers and SemiconductorsSeptember 26, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

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

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