Error establishing database connection can be caused by a number of reasons. Its a common error which can be solved by using the right method listed below.
- Incorrect Login Credentials
- Corrupted WordPress files
- Corrupted MySQL Database
- Database server is down
- Too much traffic on your site
- Check login credentials are correct
- Check if plugin corrupted wordpress files
- Repair Database
- Check with your hosting provider
- Upgrade your hosting
Incorrect Login Credentials
WordPress uses MySQL for the Database of the website. The SQL database is where the majority of the information for your website is stored. PHP is used to query the SQL database and return the data to load in the webpae. The Error Establishing Database Connection is usually caused because one of the PHP login credentials is wrong. There is a PHP file that stores the login credentials for your SQL Database. If the login credential is wrong like username or database name then you will get this error.
To fix the issue double check all the login credential values are correct. Demonstration is to show how to confirm values on Dreamhost. If you are using a different hosting provider you will have to check how to confirm the following values:
- MySQL Database Name
- MySQL Host Name
- MySQL User Name
- MySQL Password
Process to fix error establishing database connection
- Navigate to Dreamhost web FTP: https://webftp.dreamhost.com/
- Check your FTP user
- Update FTP user to allow FTP
- Login to FTP and check wp-config.php file
- Go to Advanced MySQL Database section
- Check DatabaseName, HostName, Username, Password for MySQL Database
- Edit wp-config.php with correct login credentials
- Check your FTP User
- Update FTP user to allow FTP
- Login to FTP
Check your FTP User
- Go to Dreamhost Panel and login to your hosting account. https://panel.dreamhost.com
- Navigate to Domains -> Manage Domains
- Find your Domain and check the User under Web Hosting Column. (In the example below user is actuary_admin)
- Click Admin name to open edit user section
Update FTP user to allow FTP
- Deselect “Disallow FTP”
- Enter a easier to remember password
- Click Save Changes
**Note: This is the Username and password to connect to your web server. There is a second username and password for the MySQL Database.
Login to FTP
- Host = Domain name URL
- Enter Username and Password
- Folders showing the files on your web server will open
- Find wp-config.php file and download a copy to your computer
MySQL Login Credentials
These are the details you’ll need to confirm you have the correct login credentials in your wp-config.php file. Make sure to note down what your hostname, username, databasename and password are.
- Navigate to Advanced->MySQL Databases
- Check Hostname
- Find Database
Navigate to Advanced->MySQL Databases
For Dreamhost Hostname is typically mysql.domain.com. Often times hostname is localhost but for Dreamhost its usually mysql.domain.com so in this example host is mysql.actuarials.science
Next note your database name and user or create a new user if you want by using Actions-> Add a User.
Once you have all the login credential information its time to check that it matches whats in the wp-config.php file. Remember the wp-config file is what allows your webpages to query information from your database. Without the right login a connection to the database cannot be made and you’ll get the error.
Check wp-config is correct
Finally you check that the login credentials in your wp-config file are correct. If they are wrong fix them and should fix the error.