glow-desktop glow-mobile glow-tablet bg-header banner pattern banner pattern

# Get Sorted

shape-left

Domains / Hosting

or browse the Help Centre by category

shape-right

How to fix error an establishing a database connection in WordPress

If you encounter this error, it means that the website is unable to connect to the database. The error can be caused by incorrect database information in your WordPress settings, a corrupt database, or an irresponsive database server.

What is a database? 

A database stores information that is electronically accessed and it makes it easy to organise and retrieve data.

Steps to fix the database connection error:
  1. Update the domain’s PHP version.
  2. Check your database credentials.
  3. Repair WordPress Database.
1. Update the domain’s PHP version

If the domain’s PHP version is outdated, it can cause the database connection error. The issue can be easily fixed by updating the domain’s PHP version to the latest one available.

Update the Domain PHP version. 

If you would like to know How to update your domain PHP version, please read our Help Centre article for assistance.

Visit your website again to see if the issue has been fixed. If not resolved see Step 2.

2. Check your database credentials.

Incorrect database credentials are the most common cause of database connection errors in WordPress. Check the database credentials are correct and edit them in the wp-config.php file.

What is a wp-config.php file? 

The wp-config.php file is a WordPress configuration file that contains important WordPress settings including the database information.

Important! 

The wp-config.php file contains crucial information about your website. We advise that you do a backup of your website BEFORE editing the wp-config.php file in case you make errors.

Backup your website. 

If you would like to know How to restore a backup using Afribackup, please read our Help Centre article for assistance.

  • Under the shared hosting section, select your domain on the right-hand side.
  • Click on ‘Website Manager’.

You will now be in cPanel or CWP control panel.

  • Under the Files section, select ‘File Manager’.
  • On the left-hand side select the ‘public_html’ folder.
  • Select the ‘wp’ folder below that.
  • Right-click on the ‘wp-config.php’ file.
  • Select ‘Edit’ from the menu.
  • Find ‘MySQL settings’ section and check if the following information is correct:
    • Database name.
    • Database password.
    • Database server.
How to find database credentials: 
  • Go to the ‘DATABASES’ section in cPanel or CWP.
  • Select ‘MySQL Databases’.
  • You will then see the database management page with the username and name.
  • Scroll down to change the password if necessary.
  • If you made any changes to the database details, click ‘Save Changes’ or ‘Close’ if no changes were made.

Revisit your website to see if the issue has been resolved. If it is not resolved, please see Step 3.

3.1 Repair WordPress Database in cPanel

If you get a different error in the wp-admin, for example, ‘One or more database tables are unavailable. The database may need to be repaired', you then need to take steps to repair your database.

  • Log into cPanel.
  • Under ‘DATABASES’, select ‘MySQL Databases’.
  • Under ‘Modify Databases’, select the ‘Repair Databases’ drop-down menu and select the database that needs to be repaired.
  • Click on ‘Repair Database’ button.

Try visiting your website again to see if the issue has been fixed.

3.2 Repair WordPress Database in CWP

If you get a different error in the wp-admin, for example, ‘One or more database tables are unavailable. The database may need to be repaired’, then you need to take steps to repair your database.

  • Log into CWP.
  • Select ‘Databases’ from the left-hand side menu.
  • Select ‘Mysql Manager’ below.
  • Click on the ‘repair’ icon of the database you want to repair.
  • You will get a pop up on the top-right corner of the screen showing the database has been repaired successfully.

Try visiting your website again to see if the issue has been fixed.

Understanding hosting errors. 

If you would like to know more about other Hosting errors messages, please read our Help Centre article for further assistance.

Afrihost Network Status

See the status of our broadband, mobile and hosting networks

For more details, visit our Network Status Page

ClientZone - just like magic

Manage products  .  Make payments  .  Check balances  .  Top up your account

Manage Products
Make Payments
Check Balances
Top Up your Account