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).
- 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.
- 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:
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
htopfor your server first with this command:
apt-get install htopthen type
htopthen 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.