If you are running your WordPress website on a VPS {Virtual Private Server}, the chances that you would encounter “error establishing a database connection” is quite high. Knowing how to fix this error is a must for both web developers and operators of the websites, but first, let’s understand what causes the error.

What are the causes of error establishing a database connection

  1. Wrong configuration of the wp-config file. Any mistake in the configuration would result in an error.
  2. Database crashing {If the MYSQL/MariaDB crashed, the WordPress PHP framework and apache would be able to access the database resulting in an error}.
  3. Database corrupted{caused by plugins that corrupted the database}.

How to fix error establishing a database connection for VPS hosting

Time needed: 20 minutes.

How to fix error establishing a database connection for VPS{Virtual Private Server} WordPress Website

  1. Open the terminal

    Windows key + R. Then type in cmd to open up the terminal.Open the terminal to access the SSH

  2. Open the SSH server

    Input the SSH server IP and Password.
    ssh root@{the ssh server ip.address}
    root@{the ssh server ip.address} password:{the ssh server password}
    Accessing the SSH root server

  3. Check the Database{MYSQL/MariaDB}.

    Checking the database on the terminal to make sure that the database is functional.
    Type “sudo service mysql status“.
    Green means that the database is running.{This means that VPS MYSQL /MariaDB database hasn’t crashed }.
    Red means that the database has crashed.
    If the database is down then restarting the database is the next step.Check SSH server to make sure it's active

  4. Restarting the Database{MYSQL/MariaDB}.

    Type “systemctl start mariadb“.
    This will restart the Database.
    Open up website http://yourwebsite.com. The error establishing a database connection won’t appear the problem has been solved.
    Restart the database

This isn’t the only solution to this error “Error establishing a database connection” for WordPress website. If after restarting the database and the error is still present. The next step is to disable all the plugins.

Read Now: How to speed up WordPress website

Steps for fixing the “error establishing a database connection” for VPS hosting a WordPress website caused by plugin.

1. To have a better virtual of the VPS file contents. Download a SFTP file manager from Winscp and access the files.

Winscp File Manager

2. Disable the plugin by just renaming the folder. Example renaming the folder to “disable.plugin”.

3. Check your website http://yourwebsite.com and if the error isn’t there. Then disable each plugin by simply remaining them till the problematic plugin is found.

This is the best possible solution and fix for “Error establishing a database connection” for VPS hosting a WordPress website.

Author

Egbo Munachi is a mechatronics engineer and owner of the Chincotonaija online shop. Likes include gaming, watching tv series, ping-pong, and programming.

Write A Comment

Don't miss our new blog post!

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!