How To Fix “Error Establishing A Database Connection” In WordPress

Have you ever thought of how your website actually works? It usually doesn’t depend on the CMS, the formula is pretty universal. The system stores the information in the MySQL database and connects to it when it needs to get it back or write down more.

Sometimes you may experience difficulties caused by this exact formula. Your website can go down hard and give you the MySQL database connection error.

你处理WordPress网站吗? If you read this article and visit this blog, I assume yes. Then you should’ve stumbled upon this common WordPress error called the ‘Error Establishing A Database Connection’.

Today I’d like to take a deeper look into it and tell you what may be the reasons for this error and how to fix it on your side if possible.

Oh, 顺便说一下, 即使我的办法不管用, 无论如何,我会给你一个关于如何修复它的提示!


常见的原因是什么

在尝试解决这个问题之前, I would recommend checking what the basic reasons for this mistake are.

  • Your login and password credentials do not match the mentioned ones in the wp-config 文件. 这是最常见的事情之一. Especially, when you transfer your website from the localhost to the hosting
  • Your database may have been screwed up due to the technical problems of the hosting provider
  • You have installed a corrupted plugin or a theme that has crushed your database
  • Your website cannot deal with the traffic load you get

These are the reasons, and you should determine which one you faced this time. In order to do that, I’d recommend you try all the ways of fixing this that I’ll give you further.

然而, 你应该永远记住安全第一, so prior to our fixing process you should backup your website. It will ensure that your website will not get more screwed in case you do something wrong.

First, go to your FTP server and download all the 文件s you have there. Download, literally, anything connected to your website, it’s really important.

Then go to your database and export all the tables to the .sql文件.


建立数据库连接错误


你如何解决这个问题

First of all, I recommend you checking up your wp-config 文件. 你可以在你网站的主文件夹里找到它. 它被称为“wp-config”.php的, 您可以使用任何文本编辑器打开它, Brackets or Sublime in case you are a developer and have those on your computer.

Then simply scroll and look for the following part of the code:

/** WordPress的数据库名称
定义( “DB_NAME”, “database_name_here” );
 
/** MySQL数据库用户名*/
定义( “DB_USER”, “username_here” );
 
/** MySQL数据库密码*/
定义( “DB_PASSWORD”, “password_here” );
 
/** MySQL主机名*/
定义( “DB_HOST”, “localhost” );


Now make sure that these credentials actually match the ones from your hosting provider dashboard. 为了检验这个, go to the dashboard and visit the FTP and MySQL sections and check if the ones you were given by the provider match the ones in your php-config 文件.

Oh, I should also mention that your Database host should always be set correctly. When you just upload your website from the localhost to the external server, you should change the DB_HOST value from the ‘localhost’ to the one you have been given by your hosting provider.

If everything is alright, yet you are still getting this error, let’s see what else we can do.

I’m not sure if you know, but you can ask WordPress to repair your website’s issues for you. In order to do that you should perform a few simple moves.

Go back to your wp-config 文件 and add the following line:

定义(“WP_ALLOW_REPAIR”, 真正的);
Once you’ve saved it and applied the changes, you should go to the /wp-admin/maint/repair.php page, and you will see the following message from WordPress.

建立数据库连接错误

You have two options here: Repair Database and Repair and Optimize Database.

就我个人而言, I recommend you going with the second option because it gives a deeper look at your issue and may fix it not only by repairing it but also by optimizing it according to its own guidelines.


有帮助吗??

现在让我们看看它是否对你有帮助. Do you still get this stupid error that makes you wanna crash your laptop?

别担心,我的朋友. 我要告诉你们这个很棒的功能来自 Templateog体育首页 我最近用过的. They’ve got their very own Service Center, and they can fix anything you need. 和他们联系就行了, and they will help you fix any error and perform any customizations you need.

One of my previous projects has been customized and prepared for the release by these guys. 我的客户对结果非常满意, and I was not getting a headache by all those errors that could have appeared.


相关的帖子

插件 and 教程 to Modify Your WordPress Database Safely

Setting up Database for Social Media Websites – Some Basics to Know

Six WordPress 插件 to Install on Every WordPress Site



斯蒂芬•陈

Inspires and passionate about what they are doing people work much better and create much more interesting projects. I strongly believe in its statement, so I do my best to inspire other people with my articles.

在你的电子邮件中添加更多内容

订阅 to our newsletter and access exclusive content and offers available only to og体育首页Post subscribers.

发送成功!
服务器错误. 请稍后再试.