The “error establishing a database connection” is probably one of the most comtháng and frightening errors that WordPress users can encounter. It’s definitely a cthua kém tie with the Trắng screen of death (WSOD). This error means your website is no longer communicating or has access lớn your WordPress database, và thus your entire trang web goes down. This is not something lớn be taken lightly và you should try and resolve this immediately as this can directly affect your sales, traffic, và analytics.

Bạn đang xem: Hướng dẫn xử lý lỗi error establishing a database connection

But don’t worry, today we’ll discuss some common scenargame ios that cause this error và some easy ways to get your site back up và running in no time.

What is the Error Establishing a Database Connection?

All of the information on your WordPress site, such as post data, page data, meta information, plugin settings, login information, etc. is stored in your MySquốc lộ database. The only data that isn’t stored there is truyền thông nội dung such as images & your theme/plugin/core files such as index.php, wp-login.php, etc. When someone visits your website, PHPhường executes the code on the page & queries the information from the database, which then displays it to lớn the visitor in their browser.

If for some reason this isn’t working properly, you are left with the error establishing a database connection message, as seen below. The entire page is blank because no data can be retrieved lớn render the page, as the connection is not working properly. Not only does this break the frontend of your site, but it will also prevent you from accessing your WordPress dashboard.

However, visitors might not see this error on the frontend right away. That is because your site is most likely still serving from cabịt until it expires. For example, at web5s.com.vn, all WordPress sites are cached for one hour by default. Therefore, if a site is still serving from cabít it might appear fine khổng lồ a visitor.


cPanel file manager

You need khổng lồ now check your current values against those on your server khổng lồ ensure they are correct. Follow the directions below for cPanel & web5s.com.vn users.

Chechồng Database Credentials in cPanel

The first thing khổng lồ kiểm tra is the database name. To vị this you will need lớn login khổng lồ phpMyAdmin in cPanel under the Databases section.

On the left-hand side, you should see your database name at the bottom. You can ignore the “information_schema” database as this is something used by the host. You will then want to compare that name against the DB_NAME value in your wp-config.php file. If they match, then this isn’t the problem. If they don’t match, then you need to update your wp-config.php file.

You can also verify that this is the correct database by ensuring that it contains your WordPress site’s URL. To vị this, simply cliông chồng on the database, then click inlớn the wp_options table (this might be named something slightly different for security purposes, such as wpxx_options). At the top of the table, you will see values for your site’s URL and name. If these match your current site you can rest assured you are in the right place.

If your database name was already correct và you are still getting the error establishing a database connection message then you will also want to kiểm tra your username & password. To bởi this you will need to lớn create a new PHP.. tệp tin in the root directory of your WordPress site, and đầu vào the following code. You can name it whatever you want, such as checkdb.php. Simply change the values of db_user & db_password with those that are in your wp-config.php file.

Then browse to the file on your WordPress site: https://yourtên miền.com/checkdb.php. If you get a “MySquốc lộ Error: Access denied” then you know your username or password is wrong & you will need to lớn continue to lớn the next step to remix your credentials.

Below is the message you want khổng lồ see, “Database connection is working properly.” But of course, if it was then you wouldn’t be here. Be sure to delete/remove sầu this file after you are done testing.

So next you need lớn rephối your username và password. In cPanel, cliông chồng on MySQL Databases under the Databases section.

Scroll down & create a new MySQL user. Try và pick a unique username and password so that they can’t easily be guessed. The password generator tool they provide actually works great. Then clichồng on “Create User.” You could alternatively also change the password on this screen for the current database user that already exists.

Then scroll down và add your new user to your database. The next screen will ask which privileges you want to lớn assign, select “All Privileges.”

Then take those new credentials and update your wp-config.php file. You will want to lớn update the DB_USER and DB_PASSWORD values. You could also run the test file again from earlier. This should then resolve your credentials issue. If not, it could be that you still have sầu the wrong hostname (DB_HOST). Some hosts use different values, see a danh mục of some common DB host values. Typically this will simply be localhost. But you can always reach out to lớn your hosting provider or check their documentation if you aren’t sure. Some might also use instead of localhost.

If you have followed everything above sầu and are still receiving the error establishing a database connection message, then proceed khổng lồ the next troubleshooting steps below.

Chechồng Database Credentials With web5s.com.vn

If you are a web5s.com.vn user, the process of checking your credentials against your wp-config.php file and the hệ thống are much easier! All you need to lớn vị is clichồng on the info section of your site, & at towards the bottom, you will see the database name, database username, & database password. By mặc định, web5s.com.vn uses localhost for the DB_HOST.

Then take those new credentials and update your wp-config.php file. You will want to lớn update the DB_USER và DB_PASSWORD values. This should then resolve your credentials issue. If you need to lớn rephối these credentials, simply reach out to our tư vấn team. If you have sầu followed everything above sầu and are still receiving the error establishing a database connection message, then proceed lớn the next troubleshooting steps below.

2. Repairing Corrupt Database

In some cases, it could be that your database has become corrupt. This can occasionally happen (although not very often) as over time hundreds of tables are constantly added/removed by new plugins & themes. If you try to login khổng lồ your WordPress site’s dashboard & are receiving the following error, it means your database is corrupt: “One or more database tables are unavailable. The database may need khổng lồ be repaired.” It is important khổng lồ note that you might only see this error on the back-kết thúc, whereas you see the error establishing a database connection message on the frontend.

Our customers fix this error in minutes right from their Myweb5s.com.vn dashboard. Try web5s.com.vn for Free.

Xem thêm: Cây Phong Thủy Cho Người Mệnh Mộc, Cây Hợp Mệnh Mộc

"}" data-sheets-userformat=""2":6659,"3":"1":0,"4":"1":2,"2":16777215,"12":0,"14":"1":2,"2":0,"15":"Roboto, RobotoDraft, Helvetica, Arial, sans-serif"">

WordPress actually has a database repair mode which you can initiate. Simply add the following khổng lồ the bottom of your wp-config.php tệp tin.

define("WP_ALLOW_REPAIR", true);

Then browse to lớn the following location on your WordPress site: https://yourdomain.com/wp-admin/maint/repair.php. You will then have sầu the option khổng lồ repair the database or repair and optimize the database. Since you are probably troubleshooting an outage on your site at the moment, we recommover going with the repair database option as it is quicker.

After running the repair of the database above sầu, ensure that you remove sầu the line of code you added lớn your wp-config.php tệp tin, otherwise anyone could run the repair. If you are running cPanel you can also run a repair from within the MySquốc lộ databases screen.

Or you could run a repair from within phpMyAdmin. Simply log in to phpMyAdmin, cliông chồng on your database, and select all the tables. Then from the dropdown click on “Repair table.” This is essentially just running the REPAIR TABLE command.

And finally, your other option would be to lớn run the repair using WP-CLI with the following command:

wp db repairSee more documentation on usage in the WordPress developer resources.

If you are wanting to lớn optimize your database, we have sầu some great tutorials on how to optimize WordPress revisions for performance, along with how to convert your MyISAM tables to InnoDB. If you are still having issues on your site, then proceed khổng lồ the next troubleshooting step.

Suggested reading: How khổng lồ Fix the “MySQL Server Has Gone Away” Error in WordPress.

3. Fixing Corrupt Files

The next possible reason you might be seeing the error establishing a database connection message is that your files have sầu become corrupt. Whether this originated from an issue with transferring files via FTPhường., a hacker gaining access lớn your site or a problem with your host, you can quickly fix this. However, again we recommover taking a backup of your site before trying this.

You are basically going to lớn replace the core version of WordPress on your site. You aren’t touching your plugins, themes, or media, just the WordPress installation itself. To vì chưng this, you will need to lớn download a fresh copy of WordPress from WordPress.org.

Unzip this file on your computer. Inside, you will want khổng lồ delete the wp-content folder, as well as the wp-config-sample.php tệp tin.

Then upload the remaining files via SFTP lớn your site, overwriting your existing files. This will replace all the problematic files & ensure you have fresh ones that are clean and not corrupted. It is recommended to clear your browser cađậy after doing this. Then kiểm tra your WordPress site to see if the error still exists.

4. Issues With Your Database Server

If nothing above sầu has helped resolve sầu your issue, then we highly recommkết thúc checking with your hosting provider as it could be an issue with your database VPS. For example, if there are too many concurrent connections to lớn your database at once, it could generate the error. This is because a lot of hosts have sầu limits on their servers on how many connections are allowed at once. Utilizing a caching plugin can help minimize the database interactions on your site. If you are a web5s.com.vn client, you don’t need caching plugins, as we have fast server-level caching in place.

This problem can happen a lot on shared hosts as someone else could theoretically be affecting your site. This is because shared hosts utilize all the same resources on servers. This is yet another reason why we always recommover going with a high-performance managed WordPress host, so things aren’t overcrowded. It also means the environment is typically fine-tuned khổng lồ handle large amounts of traffic specifically to lớn WordPress sites.

The knowledgeable web5s.com.vn tư vấn team is always a click away on the bottom right side of the dashboard & available 24/7 if you need help. And don’t forget we have sầu representatives in to lớn assist you in both English and Spanish.

5. Restore Latest Backup

And last but not least, you can always resort khổng lồ a backup if needed. In some cases, this might be a faster way to lớn resolve the issue if you aren’t worried about losing any data between when your last backup was taken. Many hosts have their own backup restore process. Remember that you might need to lớn restore both your database & your files.

If you are web5s.com.vn user you can easily restore a backup of your site within the Backups section of your site. Simply choose the time you want lớn revert khổng lồ and cliông chồng on “Restore to lớn.” You can then select whether you want lớn restore to lớn Staging or your Live site.

You will then be prompted lớn confirm the restore. Simply enter your site name và cliông chồng on “OK.” It also creates a backup at the time of restore so you can unvì chưng the restoration if needed.


As you can see there are quite a few ways khổng lồ fix the error establishing a database connection in WordPress. The most common being invalid credentials in the wp-config.php file. Checking to lớn ensure those are correct is the best place to start. The last thing you want for a website is khổng lồ experience downtime. So hopefully one of the steps above helped you get your site baông chồng up & running. Remember, you can always restore your site from a backup if needed.

Xem thêm: Ltd Là Viết Tắt Của Co - Các Từ Viết Tắt Jsc, Plc, Inc Và Co

Have you experienced the error establishing a database connection message on your site? If so, were you able khổng lồ resolve it? Let us know below in the comments.

If you enjoyed this article, then you’ll love web5s.com.vn’s WordPress hosting platkhung. Turbocharge your trang web and get 24/7 tư vấn from our veteran WordPress team. Our Google Cloud powered infrastructure focuses on auto-scaling, performance, & security. Let us show you the web5s.com.vn difference! Chechồng out our plans