How to Fix the Error Establishing a Database Connection in WordPress


Hi, I installed and activated elementor. I was designing my home page for around one hour using elementor. Then when I clicked on publish and visited website, I got this error “Error establishing database connection”.
Whats the problem? Everything was working fine until I started using elementor. I get same error even when I try ‘

Please help !

Tutorials Point or W3School like website in wordpress

Did you made any recent changes in the wp-config.php file? I guess, no. If so, this is a hosting problem.

If you notice this issue randomly, I would suggest moving to another hosting.


Before doing anything, please take backup first.

  1. Ensure that MySQL server is running

Create a new file called testconnection.php and paste the following code in it:

$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
echo 'Connected successfully';

You can find Database name, username and password in the wp-config.php located at public_html.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

If you are able to connect, it’s okay.

Else, please contact once host to report MySQL server down issue.


No, I did not make any changes in wp-config.php. I am using Digital Ocean. This is the first time I come across this problem after site launch.


As I am using Digital Ocean, I access my files through FileZilla.
When I connect to FileZilla and click on folder ‘root’, I get error ‘root permission’ denied. I am not able to check wp-config.php file.
Note : After hosting, I had created another user in ubuntu through terminal, and I am connecting to filezilla through new user.
When I log in from user root, it says ‘permission’ is denied.


Give them permission file to 777

May be it works


I had the same issue just rebooting the server did the work for me.


Please check the correct directory

It may /var/www/html

Enter this in the remote site field in the FileZilla.


Thanks. It worked. Everything is working after reboot.


Thanks for the support. Everything is working fine after reboot.


You’re welcome :slightly_smiling_face: