This post was last updated on February 19th, 2021 at 05:29 am
The “error establishing a database connection” is probably one of the most common and frightening errors in WordPress users can encounter. It’s definitely a close tie with the gray screen of death (WSOD). This error means your website is no longer communicating or has access to your WordPress database, and thus your entire website goes down. This is not something to be taken lightly and you should try and resolve this immediately as this can directly affect your sales, traffic, and analytics.
The establishing database connection is pretty self-explanatory you that the connection with the database has been broken.
- Error in wp-config.php file
- Causes of database establishing error
- Problem with your hosting server
- Your site might have been hacked
1. Check wp-config.php file error
Please Open your wp-config.php In your WordPress Congrigration file using FTP or Cpanel File Manager. Then, check if database name, host, username and password are correct in the your config file. If you find any change in these details, correct them immediately. If you don’t know how to edit PHP files, it’s better you make yourself familiar with the basics first.
2. Scan and check if Website has been hacked
WordPress CMS is the most preferred open source platform, but is extremely vulnerable to security threats. So, it’s no surprise to see WordPress as the top target for hacking. Use a security tools or plugins to scan your website entirely and check if your website is compromised. If you find that your site has been hacked, don’t panic. Immediately change your login details and restore your website from the your website backup files.
3. Fix problems with your hosting server
It’s a good idea to talk to your WordPress hosting provider regarding the problem.
Hosting provider will be able to tell you whether your database shuts down for exceeding its quota or there is some issue with the server. If you are told that everything is fine on the server end, it’s time to check your wp-config.php file in your website.
Check Database Login Credentials
The very first thing to do is check to ensure your database login credentials are correct. This is by far the most common reason why the error establishing a database connection message occurs. Especially right after people migrate to a new hosting provider. The connection details for your WordPress site are stored in the wp-config.php file which is generally locate the root of your WordPress site.
It contains four important pieces of information that all need to be correct in order for the connection to successfully take place.
* MySQL settings
* Database table prefix
* ABSPATH
Check Database Name
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'Enter Your Database Name Here');
Check MySQL database username
/** MySQL database username */ define('DB_USER', 'Enter Your User Name');
Check MySQL database password
/** MySQL database password */ define('DB_PASSWORD', 'Enter Your Mysql Database Password');
Check MySQL hostname (server)
/** MySQL hostname */ define('DB_HOST', 'localhost');
Mymory Limit Increase
Memory limit is one popular reason of this error, it is recommended to increase the memory limit. To increase the limit, open your wp-config.php file and add the following line of code within the main PHP tags.
define('WP_MEMORY_LIMIT', '64M');
Check or edit .htaccess file
Since the problem is usually caused by a corrupted .htaccess file, you would need to edit your .htaccess file. Open your .htaccess file from the FTP or file manager and rename it with old .htaccess file. Or refresh your website and see if the problem persists. If this fixes the problem, click on settings > permalinks and save changes to reset .htaccess.
All plugins are Deactivate
You might want to check your plugins. Deactivate all your plugins by clicking on plugins ? installed plugins. Choose “deactivate” from the “bulk action” drop down and hit apply. It will automatically deactivate all your plugins. Now go to your website, refresh it and check if the error is gone. If so, activate your plugins one by one and see which plugin has caused the problem.