+254725682556 +254725052660 [email protected]
Client Area

Databases

Why Your Website Can't Connect to Its Database (and How to Fix It)

If your website shows a database connection error instead of your homepage, the cause is almost always a mismatch between the database settings in your website's code (or configuration file) and the actual database name, username, password, or host set up on your hosting account. This is especially common on custom PHP sites, since WordPress and most apps installed through Softaculous handle these settings for you automatically.

Check These Four Things First

Before changing anything, confirm exactly what your website's configuration file is using and compare it against what actually exists on your hosting account.

  1. Database host: this should almost always be localhost, not an IP address or an external hostname, unless you were specifically told to use something else.
  2. Database name and username: both cPanel and DirectAdmin automatically add your account username as a prefix, so the actual name in use is usually something like yourusername_dbname, not just dbname.
  3. Database password: make sure it matches exactly, with no extra spaces. If you are not sure, reset it rather than guessing.
  4. User privileges: a database user only works with a database it has been specifically granted access to, even if the password is correct.
If you recently moved your website to ZIPROF or restored it from a backup, the database credentials almost always change. Update your configuration file with the new values rather than reusing the old ones.

Where to Find and Fix Your Database Details

In cPanel

  1. Log in to cPanel and open MySQL Databases.
  2. Under Current Databases, confirm the exact database name, including the account prefix.
  3. Under Current Users, confirm the username exists. If you're unsure of the password, click Change Password to set a new one.
  4. Scroll to Add User to Database, select the user and database, and click Add to confirm (or re-confirm) privileges.
  5. Update your website's configuration file with the confirmed host, database name, username, and password, then save and re-test.

In DirectAdmin

  1. Log in to DirectAdmin and open MySQL Management.
  2. Check the list of databases for the exact name, including the account prefix.
  3. Click on the database to view its assigned users, or click Create New Database if it doesn't exist yet.
  4. If you need to reset a user's password, do so from the same screen and note the new password down.
  5. Update your website's configuration file with the confirmed host, database name, username, and password, then save and re-test.

Still Not Connecting?

  • Check whether your hosting account has hit its maximum database connections limit. A sudden traffic spike or a script that doesn't close connections properly can exhaust this limit and block new ones.
  • If your application runs somewhere outside your hosting account (for example, a separate server or a local development machine) and needs to reach the database remotely, remote MySQL access has to be enabled and your connecting IP address added to the allow list first.
  • Test the credentials directly in phpMyAdmin. If you can log in to the same database there with the same username and password, your credentials are correct and the problem is in your website's configuration file instead.
  • Check your account's resource usage. On shared hosting, a database that is temporarily over its allowed connections or process limit will refuse new connections until usage drops.

Once you've confirmed the four basics above and tested the credentials in phpMyAdmin, most database connection errors turn out to be a single outdated value in the website's configuration file. If you've created the database and user from scratch, see How to Create a MySQL Database and Database User for the full setup steps.