How To Fix “Error Establishing a Database Connection” in WordPress

How To Fix “Error Establishing a Database Connection” in WordPress


How To Fix “Error Establishing a Database Connection” in WordPress

This error 👆 is not something to be taken lightly and can directly affect your sales, traffic, and analytics 😬 Learn how to fix it here ✅
👉 Subscribe: https://www.youtube.com/c/Kinsta?sub_…

The “error establishing a database connection” is probably one of the most common errors WordPress users can encounter. It’s closely tied to the white screen of death (WSOD). This error means your website is no longer communicating or has access to your WordPress database; thus, your entire website goes down.

You should resolve this error immediately, as this can directly affect your sales, traffic, and analytics.

But don’t worry, in this video we’ll discuss some common scenarios that cause this error and some easy ways to get your site back up and running in no time.

ℹ️ About Kinsta

Kinsta is an award-winning Cloud Platform designed to host and manage your WordPress sites, Applications, and Databases faster and more efficiently. Trusted by 25,000+ companies worldwide, from developers, startups, and agencies, to multinational brands, we guarantee lighting-fast performance, enterprise-level security, ease of use, and exceptional support.

🚀 Try our flagship Managed WordPress Hosting plans and get $240/month worth of premium features included in every plan. That’s free unlimited migrations, 20% faster load times thanks to Google’s fastest servers and Premium Tier network backed by Cloudflare’s 275+ CDN locations worldwide, and 24/7/365 multilingual technical support from humans in less than 2 minutes.

👉 Try risk-free with our 30-day money-back guarantee Powerful Managed WordPress Hosting

👤Follow us:
https://kinsta.com/blog/
https://kinsta.com/newsletter/
https://twitter.com/kinsta
https://instagram.com/kinstahosting
https://facebook.com/kinstahosting

💡Discover all of our hosting solutions ► https://kinsta.com/



🕘Timestamps

0:00 Intro
1:00 How To Fix The “Error Establishing a Database Connection”
1:56 Check Your Database Login Credentials
6:54 Repairing Corrupt Database
9:02 Fixing Corrupt WordPress Files
10:31 Issues With Your Database Server
11:46 Restore Latest Backup



📚 Resources

🛠 How to Fix the “MySQL Server Has Gone Away” Error in WordPress
https://kinsta.com/knowledgebase/mysq

⚙️ How To Fix The “Error Establishing a Database Connection” in WordPress
https://kinsta.com/blog/error-establi

#WordPressError


Content

0 -> Hey guys, it's Alisha,
1.35 -> and today I'm gonna show you how to fix
4.02 -> the establishing a database connection error in WordPress.
7.843 -> (upbeat music)
13.5 -> The establishing a database connection error is probably
16.5 -> one of the most common errors WordPress users can encounter.
20.64 -> It's closely tied to the white screen of death.
23.58 -> This error means your website is no longer communicating
26.79 -> or has access to your WordPress database,
29.58 -> thus your entire website goes down.
32.31 -> You should resolve this error immediately,
34.23 -> as this can directly affect your sales,
36.54 -> traffic, and analytics.
38.7 -> But don't worry.
39.78 -> In this video, we'll discuss some easy ways
42.15 -> to get your site back up and running in no time.
44.76 -> Before we get too far,
46.23 -> I wanna let you know that there will be links
48.27 -> to more resources in the video's description,
50.67 -> and remember, subscribe and ring that bell
53.31 -> to get notifications for future helpful content.
56.43 -> All right now, let's get this error fixed.
63.96 -> Before troubleshooting the error,
65.97 -> we recommend taking a WordPress site backup.
69.148 -> Many of the recommendations we have for you
71.64 -> involve manipulating information in your database,
74.28 -> so you don't wanna make things worse.
76.59 -> You should always back up
78.03 -> before trying to fix things on your WordPress site,
80.49 -> no matter how tech savvy you think you are.
83.46 -> You can use a popular WordPress backup plugin
86.01 -> such as VaultPress or WP Time Capsule
89.16 -> to backup your files and database.
91.41 -> If you're a Kinsta user,
92.73 -> you can take advantage of our one click backup feature.
95.358 -> Click into your WordPress site in MyKinsta,
98.37 -> click on backups, and then on backup now.
101.01 -> You then also have the option to restore a backup
103.65 -> to production or staging, or you can manually back up
107.07 -> your MySQL database using phpMyAdmin.
110.49 -> Once you have a successful backup,
112.08 -> it is time to troubleshoot your database connection issues.
114.9 -> The first thing to do is check to ensure
117.51 -> your database login credentials are correct.
120.48 -> This is by far the most common reason why
123.54 -> the error establishing a database connection message occurs,
127.403 -> especially right after people migrate
129.57 -> to a new hosting provider.
130.98 -> The connection details for your WordPress site
133.02 -> are stored in the wpconfig.php file,
136.5 -> which is generally located at the root
138.36 -> of your WordPress site.
139.47 -> It contains four important pieces of information
142.05 -> that must be correct for the connection
144.18 -> to occur successfully.
145.56 -> Database name, MySQL database username,
149.757 -> MySQL database password, and MySQL host name.
153.87 -> To access your wpconfig.php file,
156.99 -> you can connect to your site via SFTP
160.08 -> and browse to the route of your site,
162.3 -> or if you're using cPanel,
164.49 -> you can click on File Manager,
166.41 -> browse to the root of your site
167.94 -> and right click to edit the file.
170.46 -> Here's an example of what the file looks like when opened.
174.42 -> You need to now check your current values
176.85 -> against those on your server to ensure they are correct.
180.6 -> The first thing to check is the database name.
183.36 -> To do this, you must log in to phpMyAdmin and cPanel
187.26 -> under the databases section.
189.3 -> You should see your database name at the bottom on the left.
193.05 -> You can ignore the information_schema database
196.17 -> as this is something used by the host.
198.54 -> You'll then want to compare that name
200.7 -> against the dbname value in your wpconfig.php file.
205.26 -> If they match, then this isn't the problem.
207.9 -> If they don't match, you need to update
209.67 -> your wpconfig.php file.
211.74 -> You can also verify this is the correct database
214.23 -> by ensuring it contains your WordPress site's URL.
217.08 -> To do this, click on the database
218.97 -> and then click into the WP Options table.
222.09 -> This might be slightly different
223.26 -> for security purposes such as wpXX_options.
227.58 -> At the top of the table,
228.81 -> you'll see values for your site's URL and name.
231.72 -> If these match your current site,
233.28 -> you can rest assured you are in the right place.
235.92 -> If your database name was already correct
238.29 -> and you still get the error establishing a database
240.84 -> connection message,
242.34 -> you'll also want to check your username and password.
245.4 -> To do this, you'll need to create a new PHP file
248.55 -> in the root directory of your WordPress site
250.62 -> and input the following code.
252.75 -> You can name it whatever you want, such as checkdb.php.
256.868 -> Change the values of dbuser and dbpassword
259.68 -> with those in your wpconfig.php file.
262.62 -> Then browse the file on your WordPress site.
265.758 -> If you get a MySQL Error, access denied,
269.94 -> then you know your username and password is wrong,
272.58 -> and you'll need to continue
274.08 -> to the next step to reset your credentials.
276.63 -> This is the message you want to see.
278.91 -> Database connection is working properly,
281.67 -> but of course, if it were, then you wouldn't be here.
285.06 -> Be sure to delete or remove this file
287.28 -> after you're done testing.
288.48 -> So next, you need to reset your username and password.
291.93 -> In cPanel, click on MySQL Databases
294.78 -> under the databases section.
296.934 -> Scroll down and create a new MySQL user.
301.14 -> Try and pick a unique username and password
303.63 -> so they can't easily be guessed.
305.73 -> The password generator tool they provide works excellent.
309.21 -> Then click on Create User.
311.64 -> Alternatively, you could change the password
314.34 -> in the screen for the current database user.
316.83 -> Then scroll down and add your new user to your database.
320.55 -> The next screen will ask which privileges
322.56 -> you want to assign.
323.61 -> Select all privileges.
325.65 -> Then take those new credentials
327.33 -> and update your wpconfig.php file.
330.72 -> You'll want to update the dbuser and dbpassword values.
333.9 -> You could also rerun the test file from earlier.
336.572 -> This should then resolve your credentials issue.
339.6 -> If not, you could still have the wrong host name.
342.436 -> Some hosts use different values.
345.406 -> See a list of some common dbhost values.
348.66 -> Typically, this will be local host,
350.94 -> but you can always reach out to your hosting provider
353.55 -> or check their documentation if you aren't sure.
356.64 -> Some might also use 127001 instead of local host.
361.66 -> If you followed everything so far,
363.78 -> and you're still receiving the error
365.67 -> establishing a database connection message,
368.01 -> proceed to the following troubleshooting steps.
370.05 -> If you are a Kinsta user, checking your credentials
372.69 -> against your wpconfig.php file
375.38 -> and the server is much easier.
378.15 -> All you need to do is click on the info section of your site
381.27 -> and towards the bottom you'll see the database name,
383.88 -> username, and password.
386.01 -> By default, Kinsta uses local host for the dbhost.
389.88 -> Then take those new credentials,
392.07 -> and update your wpconfig.php file.
395.55 -> You'll want to update the dbuser and dbpassword values.
399.078 -> This should then resolve your credentials issue.
402.323 -> If you need to reset these credentials,
404.43 -> contact your support team.
405.96 -> If you followed everything so far
407.79 -> and are still receiving the error establishing
409.92 -> a database connection message,
411.75 -> proceed to the following troubleshooting steps.
413.85 -> In some cases, it could be that
415.71 -> your database has become corrupt.
418.05 -> This can occasionally happen as, over time,
420.87 -> hundreds of tables are constantly added or removed
423.995 -> by new plugins and themes.
426.227 -> If you try to log into your WordPress site's dashboard
429.42 -> and are receiving the following error,
431.37 -> it means your database is corrupt.
433.23 -> One or more database tables are unavailable.
435.9 -> The database may need to be repaired.
437.91 -> It's important to note that you might only see this error
440.94 -> on the back end, whereas you see the error
443.61 -> establishing a database connection message on the front end.
446.88 -> WordPress has a database repair mode,
448.95 -> that you can initiate.
450.63 -> Add the following line to the bottom
452.4 -> of your wpconfig.php file.
455.171 -> Then browse to the following location
458.04 -> on your WordPress site.
459.654 -> You'll then have the option to repair the database
462.84 -> or repair and optimize the database.
465.72 -> Since you're probably troubleshooting an outage
467.82 -> on your site now,
468.9 -> we recommend using the repair database option
471.6 -> as it is quicker.
473.22 -> After running the repair of the database,
475.56 -> ensure that you remove the line of code
477.51 -> you added to your wpconfig.php file.
480.87 -> Otherwise, anyone will be able to access
482.6 -> the repair.php page.
485.61 -> If you're running cPanel, you can also run a repair
488.22 -> from within the MySQL databases screen,
491.22 -> or you could run a repair from within phpMyAdmin.
495.9 -> Simply login to phpMyAdmin,
498.36 -> click on your database and select all the tables.
501.27 -> Then from the dropdown, click on repair table.
504.222 -> This is essentially just running the repair table command.
510.39 -> And finally, your other option would be
512.88 -> to run the repair using WPCLI, with the following command.
522.27 -> See more documentation on usage
524.37 -> in the WordPress developer resources.
526.77 -> If you want to optimize your database,
528.78 -> we have some great tutorials
530.31 -> on how to optimize WordPress revisions for performance,
533.28 -> along with how to convert your MyISAM tables to eNode DB.
537.24 -> If you still have issues on your site,
539.16 -> proceed to the next troubleshooting step.
541.29 -> The following possible reason you might see the
544.14 -> error establishing a database connection message
547.23 -> is that your WordPress core files have become corrupt.
551.056 -> Whether this originated from an issue
553.47 -> with transferring files via FTP,
555.846 -> a hacker gaining access to your site,
558.45 -> or a problem with your host, you can quickly fix this.
562.288 -> However, we recommend taking a backup
565.59 -> of your site before trying this.
568.172 -> You're going to replace the core version
570.36 -> of WordPress on your site.
572.22 -> You aren't touching your plugins, themes, nor media,
575.13 -> just the WordPress installation itself.
577.53 -> However, you may lose any changes or custom code
580.637 -> you've added to files such as htaccess or wpconfig.php.
586.86 -> If you backed up your website before troubleshooting,
589.53 -> you have copies of those files that you can restore later.
593.02 -> To get started, you must download a fresh
595.89 -> WordPress copy from wordpress.org.
598.5 -> Unzip this file on your computer.
600.93 -> Inside, you'll want to delete the wpcontent folder
604.32 -> and the wpconfigsample.php file.
608.263 -> Then upload the remaining files via SFTP
612.45 -> to your site, overriding your existing files.
616.44 -> This will replace all the problematic files
618.99 -> and ensure you have fresh ones that are clean
621.39 -> and not corrupted.
622.44 -> It's recommended to clear your browser cache
624.87 -> after doing this.
626.1 -> Then check your WordPress site
628.26 -> to see if the error still exists.
629.82 -> If nothing so far has helped resolve your issue,
632.94 -> we highly recommend checking with your hosting provider,
635.85 -> as it could be an issue with your database server.
638.91 -> For example, if there are too many concurrent connections
641.85 -> to your database at once, it could generate an error.
645.42 -> This is because many hosts limit their servers
648.15 -> on how many connections are allowed at once.
650.94 -> Utilizing a caching plugin can help minimize
653.94 -> the database interactions on your site.
656.73 -> If you're a Kinsta client, you don't need caching plugins,
659.55 -> as we have fast server level caching.
662.04 -> This problem can happen a lot on shared hosts,
665.07 -> as someone else could theoretically be affecting your site.
668.803 -> This is because shared hosts utilize all the same
672.149 -> resources on servers.
674.4 -> This is another reason we recommend using
676.38 -> a high performance managed WordPress host,
678.66 -> so things aren't overcrowded.
680.28 -> It also means the environment is typically
682.53 -> fine tuned to handle large amounts of traffic,
685.329 -> specifically to WordPress sites.
687.84 -> The knowledgeable Kinsta support team
689.73 -> is always a click away, on the bottom right hand side
692.49 -> of the dashboard and available 24/7 if you need help.
697.14 -> And don't forget, we have representatives
699.09 -> to assist you in multiple languages
701.34 -> including English, Spanish, French, Italian, and Portuguese.
705.6 -> And last but not least, you can always resort
708.54 -> to a backup if needed.
710.34 -> In some cases, this might be a faster way
712.53 -> to resolve the issue, if you aren't worried
714.27 -> about losing any data between when
715.95 -> your last backup was taken.
717.33 -> Many hosts have their own backup restore process.
720.48 -> Remember that you might need to restore
722.49 -> both your database and your files.
724.77 -> If you are a Kinsta user, you can quickly restore a backup
727.98 -> of your site within the backups section of your site.
731.443 -> Choose the time you want to revert and click on restore to.
735.75 -> You can then select whether you want to
737.58 -> restore to staging or your live site.
742.74 -> You'll then be prompted to confirm the restoration.
745.86 -> Enter your site name and click on okay.
748.83 -> It also creates a backup at the restoration time,
751.92 -> so you can undo the restoration if needed.
754.11 -> Have you experienced the error
755.91 -> establishing a database connection message on your site?
759 -> If so, were you able to resolve it?
761.4 -> Let us know in the comments below.
764.7 -> Looking for a quality local development solution?
767.87 -> With DevKinsta, in a single click, you can design,
771.24 -> develop and deploy new WordPress projects
773.97 -> from your local machine.
775.59 -> Plus it's 100% free to use, even if
779.04 -> you aren't a Kinsta customer.
781.38 -> Download it today at kinsta.com/devkinsta.
785.257 -> Thank you so much for watching.
787.02 -> If you found this video helpful,
788.4 -> please don't forget to like, subscribe
790.89 -> and hit the notification bell
792.21 -> for more tutorials, explainers,
793.86 -> and helpful content like this.
796.367 -> (upbeat music)

Source: https://www.youtube.com/watch?v=s0fy0GvSpeA