Troubleshooting WordPress – Error Establishing Database Connection

WordPress is an amazing Content Management System that uses a database management system called MySQL or MariaDB. But if you’ve surfed the web, you’ve probably come across the Error Establishing a Database Connection. Sometimes database’s can get corrupted, run into issues or your server can get overloaded. There are numerous reasons websites can run into issues. In the video above, I share with you some tips on how you can resolve the issue.

What Does “Error Establishing a Database Connection” mean?

As mentioned above, WordPress is a dynamic CMS which means it uses several coding languages. For the server side language, it uses PHP which powers over 83% of dynamic websites online and some big companies use PHP. PHP works in conjunction with MySQL which again, is the database. PHP needs to connect to the database in order to generate the content. If it’s unable to do so, then that’s when you get the error which I demonstrate how to fix in the video.

What Causes the Error Establishing a Database Connection?

There are several reasons why this can happen from:

  • Incorrect Database Credentials
  • Unresponsive Database Server
  • Corrupted WordPress Files
  • Corrupted Database
  • Sometimes, it just happens. That’s tech for you.

Let’s Fix This

Make sure to watch the video which provides a walk through on how to get all this done.
Below are a few code snippets you can use to help you along the way.
The code snippet below goes in your wp-config.php file.


define ( 'WP_ALLOW_REPAIR' , true);

The code snippet below is used in a temporary file we place in the root of our website file manager to check if we have the correct user credentials.


$test = mysql_connect('localhost', 'your user name', 'your password');
if (!test) {
die('MySQL Error: ' . mysql_error());
}
echo 'Database connection is working!';
mysql_close($test);

As I mention various times throughout the video, it’s always best to have a backup of your website files and database.

You should have multiple backups of your WordPress Website/Blog if possible. I like using the Duplicator Plugin and also like taking a backup of my database with phpMyAdmin and I download all my files including the WordPress Core with a free FTP program called FileZilla.

Duplicator Plugin:
https://youtu.be/U7RENdkGEaA

Learn To Code a WOrdPress Theme:
https://youtu.be/pEJ2IzYOx5c

Make sure to watch the whole video and when it comes to replacing the core files, you won’t be replacing the wp-content folder and your wp-config.php file & htaccess file. Those files and folders should not be replaced since they are vital to your website.

When you see the Error Establishing a Database Connection, it can cause you a lot of headaches trying to figure out what went wrong. Sometimes, it’s just technology not functioning properly. Fortunately, there are ways to resolve this and I’m glad to share them with you in the video.

Don’t forget to subscribe and learn how to create awesome WordPress Websites, Blogs, Themes and Plugins.

Get DevWP - WordPress Development Training Theme

Find Me On