Fix Wordpress Error Establishing A Database Connection

  -  

Are you seeing the ‘Error establishing a database connection’ notice on your WordPress website? It is a fatal error that makes your WordPress trang web inaccessible lớn the users.

This error occurs when WordPress is unable lớn make a connection lớn the database. A number of things can affect your WordPress database connection which makes it a bit difficult for beginners khổng lồ troubleshoot.

In this article, we will show you how to lớn easily fix the error establishing a database connection in WordPress.

*

What Causes Error Establishing a Database Connection in WordPress?

The ‘Error establishing a database connection’ issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database VPS.

*

A database is a software which makes it easy lớn store, organize, & retrieve data inkhổng lồ other software.

As a content management system, WordPress uses a database khổng lồ store all your content và other website data. It then connects lớn the database each time someone visits your website.

WordPress needs the following information for connecting to the database:

Database nameDatabase usernameDatabase passwordDatabase server

This information is stored in your WordPress configuration file called wp-config.php.

If any of these items are incorrect, WordPress would fail to lớn connect lớn your database server, và you’ll see the ‘Error establishing a database connection’ error.

It is one of the most common WordPress errors. Apart from incorrect credentials, this error can also appear if the database hệ thống is down, or the database files are corrupt.

Bạn đang xem: Fix wordpress error establishing a database connection

Let’s take a look at how khổng lồ fix error establishing database connection issue in WordPress with step by step troubleshooting.

1. Cheông chồng Your WordPress Database Credentials

The most comtháng reason for database connection error in WordPress is incorrect database credentials. If you have sầu recently moved your WordPress site khổng lồ a new host, then this could be the most likely reason.

Your WordPress database credentials are stored in the wp-config.php file. It is the WordPress configuration tệp tin that contains important WordPress settings including database information.

If you have not edited wp-config.php tệp tin before, then take a look at our guide on how to edit wp-config.php file in WordPress.

You’ll be looking for the following lines in the wp-config.php file.

// ** MySquốc lộ settings - You can get this info from your web host ** ///** The name of the database for WordPress */define( "DB_NAME", "database_name_here" );/** MySquốc lộ database username */define( "DB_USER", "username_here" );/** MySquốc lộ database password */define( "DB_PASSWORD", "password_here" );/** MySQL hostname */define( "DB_HOST", "localhost" );You need khổng lồ make sure that the information for the database name, username, password, and database host is correct.

You can confirm this information from your WordPress hosting account dashboard. Simply log in to lớn your hosting trương mục và click on MySQL databases under the database section.

*

This will take you lớn the database management page in your hosting dashboad. From here, you can find out your database name & the username.

*

Below that you will find the database users và link to change the user password.

*

Once you have confirmed your database name, username, & password, you can change that information in your wp-config.php file if needed.

After that, try visiting your website again lớn see if the database connection error has gone.

If you can still see the error, then this means that something else is wrong. Continue reading for more troubleshooting steps.

2. Chechồng Your Database Host Information

If you are confident that your database name, username, và password information is correct, then you may want khổng lồ make sure that you are using the correct database host information.

Most WordPress hosting companies use localhost as your database host. However, some managed WordPress hosting companies use separate servers to lớn host databases. In that case, your database host information will not be localhost.

You need khổng lồ liên hệ your WordPress hosting company lớn confirm your database host information.

3. Repair WordPress Database

If you are getting a different error on the wp-admin, for instance, something lượt thích “One or more database tables are unavailable. The database may need to be repaired”, then you need khổng lồ repair your database.

You can vày this by adding the following line in your wp-config.php file. Make sure to add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

define("WP_ALLOW_REPAIR", true);Once you have sầu done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

*

Note: the user does not need khổng lồ be logged in to lớn access the database repair page. Once you are done repairing and optimizing your database, make sure to lớn remove this code from your wp-config.php.

4. Check if Your Database Server is Down

If everything seems khổng lồ be correct, and WordPress still cannot connect to the database, then your database VPS (MySQL server) may be down.

This could happen due lớn heavy traffic on a hệ thống. Basically, your host hệ thống just cannot handle the load (especially when you are on shared hosting).

Your site will get really slow & for some users it may even output the error. So the best thing you should do is get on the phone or live chat with your hosting provider & ask them if your MySQL server is responsive sầu.

Xem thêm: Cách Tạo Nick Avatar (Team) Ko Dùng Nữa!, Hướng Dẫn Đăng Kí Nick Avatar Chứa Ký Tự Đặc Biệt

If you have other websites running on the same hệ thống, then you can check those sites lớn confirm that your SQL VPS is down.

If you bởi vì not have any other site on the same hosting trương mục, then simply go to your hosting dashboard & try to lớn access phpMyAdmin & connect the database.

If you can connect, then we need to verify if your database user has sufficient permission. Create a new tệp tin called testconnection.php & paste the following code in it:

Make sure to lớn replace the username và password. You can now upload this tệp tin to lớn your trang web và access it via web browser.

If the script connected successfully, then it means that your user has sufficient permission, và there is something else that is wrong.

Go baông xã to your wp-config file lớn make sure that everything there is correct (re-scan for typos).

Other Solutions That Have Worked for Users

If the above-mentioned troubleshooting tips failed lớn fix the database connection error on your trang web, then you may try these additional steps.

Reported by our users, these steps have helped some users resolve the database connection error on their websites.

1. Update WordPress Site URL

Try updating the WordPress site URL using phpMyAdmin. Simply access phpMyAdmin from your hosting trương mục dashboard, and select your WordPress database.

*

After that click on the SQL menu on the top và enter the following MySQL query.

UPDATE wp_options SET option_value="YOUR_SITE_URL" WHERE option_name="siteurl"Don’t forget khổng lồ provide your own site URL và change wp_options to your own table name as you may have changed the WordPress table prefix.

2. Rebooting Web Server

Users on dedicated servers, local server, & virtual private servers (VPS) can try rebooting their servers.

This will restart your website và database hệ thống which may fix some temporary glitches causing the error.

3. Ask for help

If everything else fails, then you may need khổng lồ liên hệ your website hosting company. All good WordPress hosting companies will help you troubleshoot the problem, point you in the right direction, or even fix it for you.

You can also hire WordPress developers from Codeable that can help you fix this issue for reasonable rates. The best part is that these developers are highly-vetted by Codeable team, so you know they can be trusted.

Xem thêm: Bảng Giá Gửi Bưu Điện Trong Quá Trình Bán Hàng, Tổng Công Ty Chuyển Phát Nhanh Bưu Điện

We hope this article helped you fix the error establishing a database connection in WordPress. You may also want to lớn see our WordPress troubleshooting guide for tips on resolving WordPress issues on your own.

If you liked this article, then please subscribe khổng lồ our YouTube Channel for WordPress Clip tutorials. You can also find us on Twitter & Facebook.