Fixing “Error establishing a database connection” in your WordPress website on Ubuntu

This post is also available in: Tiếng Việt (Vietnamese)

I. “Error establishing a database connection”, what is this?

This is very popular error message when we can not connect to database with WordPress CMS.

Because this error message is come from WordPress, so you will have 2 way to check where this error come from (In my experience).

II. Solutions

  1. Check the wp-config.php in root directory of WordPress project

    You need to make sure 3 options above is correct to connect with database.

  2. If your config is correct but the error message still exist, this time you need to check mysql application in your server (Ubuntu).
    Check the status of the mysql with this command: service mysql status.
    Normally, the output will be like this: mysql stop/waiting.
    So, you need to start again mysql with this command: server mysql start. If success, the problem is solved.
    If not success and the output look like this: start: job failed to start. This time you need to check RAM status of your server with htop module. Make sure to install htop for your server first with this command: apt-get install htop then type htop then start checking.

    Check the RAM, if RAM nearly full, that mean RAM is too busy to run mysql, so it place mysql in queue to process, that why mysql is not working and can not start.
    This time you need to add caching memory to reduce workload for RAM with this following guide and start mysql again.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: