5 Fixes Error Establishing A Database Connection In Wordpress
I’ll show you 5 ways how to fix “Error establishing a database connection” in WordPress. We will try 5 different ways to fix this annoying WordPress error.
Useful links and code:
define(‘WP_ALLOW_REPAIR’, true);
www.yourdomain.com/wp-admin/maint/repair.php
Why does the WP error appear?
To fix the issue, you need to know what is causing this error.
WordPress is written in PHP coding language, and to store any of your article text or plugin settings inside WordPress PHP needs to store and retrieve things from a database, and that database is run on a software called MySQL.
What this error is telling you, is that for some reasons PHP is not able to connect to the database.
There are 3 main reasons why this error appears.
1. Wrong database credentials
2. Corrupt files
3. Or issue with the database server
Before we start, make sure you have a backup, even if the website doesn’t work right now, it takes only a few minutes and it will give you peace of mind.
1. Check for any credential issues
The first step is to check that you have the right database user credentials. And this is the most usual cause for the “error establishing a database connection” in WordPress, especially when you are setting up a new WordPress website.
You need to have access to cPanel to check this. If you are using a managed WordPress that doesn’t have this, I would just contact your web host, they should be able to help you since they are managing WordPress for you.
If you have multiple domains, it’s important that you find the root folder of your domain.
If it’s your primary domain, then your root folder is probably going to be inside the public_html folder. If it’s an add-on domain, then it usually the root folder is just the domain name. In my case, it’s called s toremonkeywp.com
Then we will compare the database user credentials in cPanel with the wp-config file.
I’m here in my web hosting’s dashboard, and I’ll go to my Cpanel. Pretty much all web hosts have Cpanel (except if you have managed WordPress plan, then you need a use FTP client to debug this issue, but honestly you should just reach out to your web hosting support).
If you have multiple databases and you are not sure which one is which, then head to your Cpanel – myphpAdmin and open first database – and open wp_options table, here at top you will see the URL of the website connected to this database
Compare wp-config with Cpanel databases and check if you have the right:
1. DB name: myphpadmin
2. User name: in CPanel
3. Password: in Cpanel, and show where you change
Next, you need to check that you have assigned a user to your database in cPanel.
Then check that your database user has sufficient permissions.
If everything looks okay, but the website still doesn’t work.
Then just create a new user, and remember to assign it to the right database.
2. Check that the database host is correct
Since we are already in the wp-config file, let’s check that the DB host is the correct one, in most cases, it should be localhost.
Page with local hosts:
https://wordpress.org/support/article/editing-wp-config-php/
3. Enable repair database page in WP.
The next step is to auto repair the database.
If you are getting a different error on the wp-admin, for instance, something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.
define(‘WP_ALLOW_REPAIR’, true);
www.yourdomain.com/wp-admin/maint/repair.php
REMEMBER TO REMOVE THE CODE, as it can be accessed by anyone.
4. Disable plugins
Sometimes your plugins mess up your database and just by disabling them the WordPress Error establishing a database connection will go away.
You can do this by renaming the plugin folder inside the file manager. You can just rename it to something like plugins-old.
5. Check if Your Database Server is Down
You can see this in cPanel stats, these stats show how much load is on your server.
If it still doesn’t work? Now if it still doesn’t work I would contact your web hosting support team and let them help you.
And if even they can’t help you, and if you have a recent backup then you could also try to restore your website to that point. I mean you might lose some data, but at least your website is back up.
Bonus:
I’ve also read online that some people have fixed the issue by renaming their website name in the wp_options table in myPhpAdmin.
And that for some people it helped to re-install WordPress core files, but if you want to get that far make sure back up what you already have. I’ll leave links to those 2 solutions in the description.
MY WEBSITE SETUP:
Web Hosting: https://punchsalad.com/hostpapa/ (60% discount)
Domains: namecheap.pxf.io/rorrB
WP plugins: https://punchsalad.com/recommendations?utm_campaign=wpDbConnectionError&utm_medium=social&utm_source=youtube
Some of the above links are affiliate links.
Source
The post 5 Fixes: Error Establishing a Database Connection in WordPress appeared first on Wordpress Tip Guide Support Solution.
Artikel ini hanyalah simpanan cache dari url asal penulis yang berkebarangkalian sudah terlalu lama atau sudah dibuang :
https://www.jonloh.com/5-fixes-error-establishing-a-database-connection-in-wordpress/