Fix Error Establishing A Database Connection Wordpress





When you start using WordPress, you will certainly encounter some errors, some serious errors, others not so much. That is inevitable; it could be your fault, sometimes the system is broken, someone fails at their job, a disaster happens - anything can cause an error.

Even something as good as an increase in traffic can disrupt your WordPress site, leaving you with an error and a bad taste in your mouth.

Now, like any human-made project, WordPress is prone to sharing bugs, none of which are as difficult and difficult as Error Database connection establishment error Error That's because this error doesn't come with details of what went wrong, although it can be caused by some things, of course - just adding salt to the wound.

All you get when you try to load your site is:

Error establishing a connection

In today's article, we will dig a little deeper into this WordPress bug and then present some solutions you can use to restore your site to its former glory. Enjoy and please share your tips and solutions, or ask your questions in the comment section at the end.

Error What does a database connection error mean?

To give you an insider's understanding of the EEDC bug, we first need to split WordPress into two basic components.

WordPress is built with PHP (e.g. index.php, sidebar.php, etc.) and MySQL. PHP is in charge of all the functions on your WordPress site (e.g. posting comments, posting posts and pages, etc.) and MySQL is in charge of data storage.

For example, when you enter your URL into the address bar and press enter, PHP will access, fetch and display the content of the homepage (index.php) from your MySQL database. However, such images, videos and media are stored in the wp content directory, from which they are accessed by PHP.

Your MySQL database contains all the important information that PHP needs to create your website. Now, when PHP is unable to access your MySQL database for one reason or another, you will encounter an dismay error when setting up the database to connect the message database on the screen. your picture. That's just a PHP-speak because I could not find the data I needed to incorporate your WordPress site. This is an error to show you I tried.

That said, the EEDC error may be caused by a number of reasons including but not limited to:

  • Login details are incorrect; Spelling errors, wrong quotes and extraneous spaces - Changing your database login details can block your site from accessing the database.
  • Unresponsive database server - The server where your database lives may die like a dodo; caput, unresponsive or still recovering after increasing traffic.
  • The WordPress files are corrupted
  • Corrupt database - Bad plugins, addons, themes, and data transfer interruptions can cause your database to be missing or completely corrupted.

In the next section, we will outline the most common solutions known to be effective.

Troubleshooting Error Error when establishing database connection.

Of course, we would be crazy if we tried to fix the problem without setting the cause first. If we can identify the root of the error, then when it is possible to get a viable solution.

Is your WordPress database broken?

We can start by checking if the error is a result of a corrupted database. For this, we have to check if the bug crashes the back end.

All you have to do is navigate to yoursite.com/wp-admin/. Please do not forget to replace yoursite.com with your own domain name.

If loading the user interface (for example, yoursite.com) and back-end (i.e. yoursite.com/wp-admin/) results in an EEDC error, then your database fits like a puzzle and you No need to worry yourself with the next step. You can skip all the ways to determine if you have the correct login information in your wp-config.php file.

However, if you are getting one or more database tables that are not available or something else except the infamous EEDC error, your database is corrupted and needs repair.

Don't worry a bit, because fixing your WordPress database is an easy job. You can be done in three simple steps. First, locate the wp-config.php file, located in your WordPress root directory. The root directory is the directory where your WordPress website is installed.

You can usually find this directory inside the default home directory or as public public_html. Just log in to your cPanel and navigate to File manager .

cpanel-file-manager-in-bluehost

Then navigate to your WordPress root directory:

Open file manager

Locate your WordPress root directory here

From this point on, locating your wp-config.php file will be easy:

locate -wp-config-file-in-wordpress-root-directory

Once you have access to wp-config.php, open it in edit mode. Right-click on the file to select a code editor or select a code editor in the menu:

edit-wp-config-using-the-code-Editor-menu-item

This will open your wp-config.php in a new tab. Add the following code at the bottom:

firstdefine (‘WP_ALLOW_REPAIR’, true);

Save your changes.

The above code allows you to repair your WordPress database without having to log in to phpMyAdmin manually, which can be quite difficult depending on your experience.

The second step involves navigating to yoursite.com/wp-admin/maint/repair.php. This will open the following screen:

wordpress -data-screen repair

The third step, just select one of the two database repair and repair and optimize the database, and let WordPress do the rest.

Note: When your database is repaired, be sure to delete the code you added to the wp-config.php file. Otherwise, you risk giving hackers access to your database, where they will destroy.

If fixing your database solved the error, well and well, just go ahead and pop the bubble. If you still see errors after repairing the database, the error may be caused by incorrect login details, corrupted WordPress files, or unresponsive database server.

Please check if your database login details are the problem.

Check your database credentials

Open your wp-config.php again and look for the following lines of code:

first// ** MySQL settings - You can get this info from your web host ** //
3/ ** The name of the database for WordPress * /
4define (‘DB_NAME’, ‘database_name’);
6/ ** MySQL database username * /
7define (‘DB_USER’, ‘database_user’);
9/ ** MySQL database password * /
tendefine (‘DB_PASSWORD’, ‘database_password’);
13define (‘DB_HOST’, ‘localhost’);

Details in the second parenthesis pair, in which we have ‘database ',‘ database ’, etc., will not appear as shown in the code above. These details are specific to your site and server.

Four simple lines mean:

  • ‘Database_name’ - Your database name is here, for example, ‘wordpress_vista’
  • ‘Database_user’ - Your database username is here, for example: ‘wordpress_new’
  • ‘Database_password’ - This is where you put your password, for example: ‘test! @ #! @ # ’
  • ‘Localhost’ - This is where you enter your database server. The default is 'localhost' for most web servers.

If any of these four information is incorrect, you will encounter a database connection error.

At this point, all you have to do is check these logins against those stored in your database. It is easy work.

First, check that you have the correct database name in your wp-config.php. Follow these steps:

From your cPanel, visit phpMyAdmin. In most accounts Shared Hosting , phpMyAdmin is usually in the tab database tool :

database

The first screen you will see after clicking on phpMyAdmin is the login screen:

phpmyadm

Once you are logged into phpMyAdmin, click on the tab Database To query your database list:

database-tab-in-phpMyAdmin

From the list of databases, can you see the database appearing after DB_NAME in your wp-config.php file?

database-in-phpmyadmin list

Examples of what to expect.

If you can see it, you're golden - the problem is not in the database name. If you cannot see the database in phpMyAdmin, you need to contact your WordPress hosting provider, as the problem may be their server.

If the database does not exist, you will need to restore one from the backup (if you have a backup in place) or create a new one. See why backing up your WordPress site is so important?

Suppose you have found your database and you have the correct name in wp-config.php. Now let us check that your database username, password and server are correct.

Check database username and password

Check your username and password regarding a small job. You need to create a .php file and store it in your WordPress root directory. This is the same directory where you found the wp-config.php file. Create a new .php file and name it check.php or whatever you want.

This you can do easily by opening your WordPress root directory and clicking New file on the menu:

create-a-new-php-file-in-wordpress-root-directory

When you create the file, it will appear in your root directory for a moment. Right click on it and select Edit the code , or select it and click Code editor on the menu. This will lead you to a blank page. Add the following code:

2$ link = mysql_connect (‘localhost’, ‘root’, ‘password’);
4die (‘Could not connect:‘. mysql_error ());
6echo ‘Connected successfully’;

Be sure to replace ‘localhost’ ‘root’ and ‘password’ with the database server, username and password in wp-config.php respectively. Save the changes and navigate to yoursite.com/check.php. If you receive a successful connection, then your login details are correct.

If you get unable to connect: Access denied for user 'yourusername' @ 'localhost' (use password: yourpassword), or some other error, database server, username Or your password is the culprit here.

If your login details do not work, you need to create new ones and then update your wp-config.php with new details. To get new login information, you need to create a new user, this is as easy as A, B, C.

Besides: Your problem may be the result of the final certificate, DB_HOST. By default, most web hosts use ‘localhost’, but you can try changing this to an IP address or URL according to your web server. You can receive Host list and their DB_HOST values ​​on WordPress Codex . If your server is not on the list, please contact them for this information.

Go ahead, create a new user.

Create a new password and database user

Go back to your cPanel and access the MySQL Database. It is also under database tools , the same tab you found phpMyAdmin:

phpmysql

Clicking on MySQL Database will open something like this:

mysql-database-screen

When the screen MySQL database Download, navigate down where you have it MySQL users . In this section, you will see Add new user:

Add new users

Enter the new username and password and click Create user . Note these details for your wp-config.php file.

Note: Your setup may be different, but the procedure is the same.

When you create a new user, you need to assign users to your WordPress database. This is the database shown after DB_NAME in your wp-config.php file.

To assign users to your database, go to the screen MySQL database Again and scroll down to where you will see Add users to the database:

Add new users to the database

Select the user you have just created and your database and click More . You can choose user privileges in the next screen, but that doesn't really matter. Select all privileges, if you must and save the changes.

Go back to wp-config.php and update the file with new information. Make sure there is no gap between quotes. For example, ‘your username’ is bad, but ‘your username’ is great. Also, use parentheses as opposed to quotes. Save all changes you have made to your wp-config.php.

Now, try to visit your website.

Are you still getting the error? If it is, the problem is probably broken WordPress files.

Fix broken WordPress files

Bram Valk used to have an error after including the interrupted PHP files in its footer. It could cause him a lot of trouble if he didn't know the files were the problem, so he removed the problematic files, and the error was gone.

Your error may be due to corrupted WordPress files, which doesn't worry you as other users have solved this error just by restoring their WordPress files. You need to be careful here because a small mistake can clear your entire site. First, make sure you back up your entire WordPress site before proceeding.

Then download a new copy of WordPress from WordPress.org. Unzip the package on your computer and then delete wp-config.php as well as wp content directory. This will ensure you do not break your existing wp-config.php file. It will also ensure you do not lose the themes, plugins, and media stored in wp content after you restore WordPress.

Once you have this, download the remaining files to your WordPress root directory using FTP or File manager. This will replace all problematic files.

Try reloading your site and if you still see errors, first try clearing your browser's cache. If the error persists after clearing your cache, please ask your questions in the comments and we will come to your aid.

Also, please contact your web host because the problem may be on their side.

Final thought

At the end of the day, you should not sweat when you encounter this error. As we outlined here today, it's simple to solve, and if you encounter any issues, your web server is always by your side and calling.

We are also always here to help you. We may not fix the error (if something goes wrong with your server) but we can and will always hold your hand and help you in the best way possible.

We hope this article helped you learn how to troubleshoot database connection error in WordPress. You might also want to see our article on how WordPress beginners can avoid these 7 common errors.

Now you ...

Have you experienced and resolved this error before? What caused it, and how did you solve it? Please share your tips and solutions with us and make this Post more meaningful

Nguyen Diep

My name is Nguyen Manh Cuong. I was born in a poor village in Ba Vi district, HA NOI province - windy and sunny land. Currently

Post a Comment

Previous Post Next Post

Đọc nhiều trong tuần

10 Grands Sites de modèles PowerPoint gratuit
10 Grands Sites de modèles PowerPoint gratuit

PowerPoint est toujours le roi quand il vient à un logiciel de présentation. Il a été autour depuis des siècles et chaque nouvelle version ajoute plus de fonctionnalités et rend …

17 best home jobs in 2020
17 best home jobs in 2020

Earning Money blog access_time April 13, 2020 hourglass_empty 28 least Read Finding work from home is easier thanks to high technology. Not only suitable for tho…

How much RAM is the iPhone 12 Pro?
How much RAM is the iPhone 12 Pro?

The RAM of the iPhone 12 Pro is up to 6GB.
Based on information in the latest Xcode beta from Hiraku, it can be said that both of Apple's new iPhone 12 Pro models have 6GB of R…

JavaScript
JavaScript

JavaScript is a programming language of HTML and WEB. It is lightweight and most commonly used as part of web pages, but their implementation allows Client-Side scripts to interac…

translate