If you see the ‘Error establishing a database connection’ notice on your WordPress website, it means that WordPress cannot connect to the database. This can be caused by a number of things, which can make it difficult for beginners to troubleshoot. However, there are some easy ways to fix this error and get your website up and running again.
Step 1: Check Your WordPress Database Credentials
One of the most common reasons for a database connection error in WordPress is having incorrect database credentials. If you’ve recently moved your WordPress site to a new host, this is likely the cause.
Your WordPress database credentials are stored in the wp-config.php file, which contains essential settings for WordPress, including your database information. If you haven’t edited this file before, check out our guide on how to do so.
Please find the following lines in your wp-config.php file and edit them according to your database information.
/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘database_name_here’ );
/** MySQL database username */
define( ‘DB_USER’, ‘username_here’ );
/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password_here’ );
/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );
You need to make sure that the information for the database name, username, password, and database host is correct.
You can confirm this information from your WordPress hosting account dashboard. Simply log in to your hosting account and click on MySQL databases under the database section.
If you are using cPanel, you will find the Database section. Here you can edit the database information.
Below there, you will find the database users and links to change the user password.
Try visiting your website again to see if the error has gone away. If you are still seeing the database connection error after confirming your database name, username, and password, then this means that something else is wrong.
Step 2: Check Your Database Host Information
If you’ve checked the database login credentials and fixed any errors, but the Error Establishing a Database Connection message persists, check your database host information next.
Your WordPress database host is the server that stores all the information for your website. In most cases, this will be localhost, but some WordPress hosting companies use separate servers. If this is the case, you’ll need to contact your hosting company to get the correct database host information.
Step 3: Repair Your WordPress Database
If you are getting an error on the backend of your site that says something like “One or more database tables are unavailable. The database may need to be repaired,” you will need to repair your database.
To access it, open up your wp-config.php file and add the following code at the end:
Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php
Note: You can access the database repair page without being logged in. Once you’re done repairing and optimizing your database, make sure to remove this code from your wp-config.php.
Step 4: Check if Your Database Server Is Down
If you are still facing trouble connecting to your WordPress database, your server may be down.
There are several reasons your database host or server might be experiencing issues. It could be due to a high volume of traffic, an outage with the hosting provider, or maintenance.
- Too many simultaneous connections: Too many people are trying to access the database at the same time. That can happen if there are too many visitors to a website at once. It can also happen if someone is trying to hack into the system.
- Problems with another site on your shared hosting server: Another website on the same server as yours may contain problems, which can cause your website to run slower or have other issues.
- Hardware troubles: Your database server may contain hardware issues, which can cause problems with your website.
If your site is running slowly or seeing error messages, the best thing is to contact your hosting provider to see if the problem is with your server.
Other Solutions That Have Worked for Users
If the troubleshooting tips mentioned above did not fix the database connection error on your website, you may try these additional actions. For some users, these steps have helped resolve the database connection error on their websites.
- Update WordPress Site URL: You can try updating the WordPress site URL using phpMyAdmin. Simply access phpMyAdmin from your hosting account dashboard, and select your WordPress database. Then enter the following query:
UPDATE wp_options SET option_value=’Your Site URL’ WHERE option_name=’site-url’
- Reboot your web server: This one might seem a little basic, but sometimes the simplest solutions are the most effective. If you host your database on your own server, try turning it off and back on. This will restart your web and database server which may fix some temporary glitches causing the error.
- Ask for help: If you are still having trouble with your WordPress site, try reaching out to your web hosting company for help. They should be able to assist you in troubleshooting the issue or even fix it for you.