How to Fix the Error Establishing a Database Connection in WordPress


#1

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 ‘mysite.com/wp-admin

Please help !


Tutorials Point or W3School like website in wordpress
#2

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.


#3

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:

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

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.


#4

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.


#5

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.


#6

Give them permission file to 777

May be it works


#7

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


#9

Please check the correct directory

It may /var/www/html

Enter this in the remote site field in the FileZilla.


#10

Thanks. It worked. Everything is working after reboot.


#11

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


#12

You’re welcome :slightly_smiling_face: