WordPress is web publishing software you can use to create a stunning website or blog. It just may be the easiest and most flexible blogging and website content management system (CMS) for beginners.
Moreover, there are a lot of things that can trigger errors connecting to your database. For example, it might be corrupt files on your website either from themes, plugins, or WordPress core itself. Knowing how to fix these issues can help you minimize the time your website spends being unavailable.
Three steps to fix the Error establishing a database connection in WordPress
In very few cases, WordPress might not be able to establish a connection to the database due to incorrect credentials. If everything else fails, you can check if your credentials are set correctly.
1. Restore a recent backup that includes your database
- In short, you should have a recent backup of your website available at all times. This backup should also include a copy of your database, so you can restore the entire website to a working state before the connection error.
- Restoring a backup without access to the WordPress admin can be tricky though. In fact, if you depend on a plugin solution, you might be out of luck altogether.
- Ideally, you’d have already set up automatic backups with your web host – and you can usually restore them from your control panel.
- If this applies to you, fixing the error establishing a database connection in WordPress is a matter of simply choosing which backup to use.
- On the other hand, if you only have access to manual backup files, you may need to upload them manually. This means both uploading your WordPress files and using a tool such as phpMyAdmin to restore a database backup.
2. Check for corrupted WordPress theme and plugin files
- In some cases, compatibility issues between plugins, themes, or corrupted files can prevent WordPress from establishing a connection to the database. Usually, this can happen right after you update a theme or a plugin, which points to one of those files as the culprit.
- However, you might be thwarted by a lack of access to the dashboard. This means you need to rule out plugins and themes by disabling them using FTP. Given this, you’ll need to use a client (such as FileZilla) to access your website.
- Go ahead and connect to your site via FTP, then navigate to the wp-content directory. Inside, you’ll find at least two folders:
- plugins
- themes
- First, you should rule out plugins as the culprit. To do so, rename the plugins folder to something else, such as plugins. disabled. This change will automatically disable all of your active plugins.
- Now try accessing your website to check if the error persists. If it’s gone, it means one of your active plugins was the culprit.
- To find out which one, return the plugins folder to its original name and head inside. Now, work your way through each individual plugin folder, changing its name each time, then checking to see if the error goes away.
- Keep disabling plugins one by one until you land on the one wreaking havoc.
- If none of your plugins are causing problems, it’s time to turn towards your active theme.
- The process here works just the same as with plugins. Navigate to the wp-content/themes directory and look for the folder that corresponds to your active theme.
- Go ahead and change the folder’s name to anything else. Doing so will cause WordPress to revert to one of its default themes, which will affect the way your site looks.
3. Reinstall WordPress core files
- So far, we’ve ruled out plugins and themes as the from being behind the error establishing a database connection in WordPress. Now, let’s check if some of your WordPress core files are the ones causing problems.
- The simplest way to fix this is to replace all your core files with a ‘clean version of WordPress. To do this, download the latest version of the core WordPress software from WordPress.org.
- Once you have the file, unpack it and delete the wp-content folder in the downloaded files, so you don’t overwrite your plugins, themes, or media files.
- To upload the clean files, access your website via FTP and navigate to your site’s root folder. Next, upload all the WordPress files from your computer.
- This process might take a while and you will need to say yes when the FTP client asks if you want to overwrite the files on your server. Also, bear in mind that if you’ve made any modifications to core files, such as your site’s .htaccess file, this process will overwrite them.
- When the upload is done, go ahead and try to access your website once more.