Cannot Connect to MariaDB MySQL Database

PHP/MariaDB/MySQL | Updated March 2026

The "Could not connect to the database" error means your website or application cannot establish a connection to your MariaDB/MySQL database. This is almost always caused by incorrect database credentials in your application's configuration file. This guide walks through every cause and fix.

Most Common Fix

Wrong Credentials in Your Config File

90% of database connection errors are caused by a mismatch between the credentials in your application config file and what is set in cPanel. Check these four values:

  • ✓ Database name
  • ✓ Database username
  • ✓ Database password
  • ✓ Database host (should be localhost)

01. Check Your Database Credentials

Open your application's configuration file and verify all four database values match what is set in cPanel.

WordPress (wp-config.php)

define('DB_NAME', 'yourusername_dbname');
define('DB_USER', 'yourusername_dbuser');
define('DB_PASSWORD', 'your_password_here');
define('DB_HOST', 'localhost');

Where to Find Your Credentials in cPanel

  1. Database name - cPanel > MySQL Databases. Your databases are listed at the top
  2. Database user - same page, listed under "Current Users"
  3. Password - cPanel does not display existing passwords. If you're unsure, click "Change Password" next to the user to set a new one. Then update your config file to match
  4. Host - always localhost for applications running on the same server

02. Verify User is Added to Database

Creating a database and creating a user are two separate steps. You must also add the user to the database with the correct privileges. This is the second most common cause of connection errors.

  1. Go to cPanel > MySQL Databases
  2. Scroll to "Add User To Database"
  3. Select your user and your database from the dropdowns
  4. Click Add, then select ALL PRIVILEGES
  5. Click "Make Changes"

For a full walkthrough, see our database user guide.

03. Database Hostname

For all applications running on the same hosting account, the database hostname is always:

localhost

Do not use your domain name, server IP, or 127.0.0.1 as the database host. Some applications may also ask for a port. The MariaDB/MySQL port is 3306 (the default). See our port reference.

04. Username Prefix

On cPanel shared hosting, all database names and usernames are prefixed with your cPanel username and an underscore. For example:

  • If your cPanel username is johndoe and you create a database called wordpress, the full database name is johndoe_wordpress
  • If you create a user called wpuser, the full username is johndoe_wpuser

Your config file must use the full prefixed names, not just the short names. This is one of the most overlooked causes of connection failures, especially when migrating a site from another host.

Tip

Keep database and usernames short. The prefix plus your name cannot exceed the character limit. Some older applications have issues with names longer than 16 characters total.

05. Password Tips

Database password issues are surprisingly common:

  • Use alphanumeric characters - some applications have trouble with special characters like $, @, or quotes in database passwords. Stick to letters and numbers if you're having issues
  • No spaces - leading or trailing spaces in the password field of your config file will cause authentication to fail
  • Reset if unsure - cPanel > MySQL Databases > Change Password next to the user. Update your config file immediately after

06. Remote Database Connections

If you need to connect to your database from outside the server (e.g., from a desktop application like MySQL Workbench or a remote script):

  1. Go to cPanel > Remote MySQL
  2. Add the IP address of the computer that needs access
  3. Use your server hostname (from your welcome email) as the host, not localhost
  4. Port: 3306

Manage your databases visually using phpMyAdmin in cPanel (Databases section). No remote access setup required since phpMyAdmin runs on the server. See our cPanel guide.

Still Getting a Connection Error?

If you've verified all credentials and the user is added to the database with all privileges, open a ticket. We can check the server-side MySQL logs for the specific error.

Open a Support Ticket

Quick Recap

  1. Check config file credentials - DB name, user, password, and host must all match cPanel
  2. Add user to database - creating them separately is not enough
  3. Host is always localhost - for same-server connections
  4. Use full prefixed names - username_dbname, not just dbname
  5. Reset password if unsure - then update the config file

Last updated March 2026 · Browse all PHP/MariaDB/MySQL articles · See also: Add User to Database | MySQL Port

  • 582 Users Found This Useful

Was this answer helpful?

Related Articles

When trying to connect to MariaDB or MySQL you receive error 2003 Cannot connect to MySQL on xxxxxx on port 3306 10060

The error 2003 "Cannot connect to MySQL on xxxxxx on port 3306 10060" means that the MySQL...

Disable MySQL strict mode on cPanel server

here are the steps on how to disable MySQL strict mode on a cPanel server:   Log in to your...

How can I find my MariaDB - MySQL version?

Method 1: Through cPanel   Log in to your Ultra Web Hosting account. Click on the cPanel...

What is the proper MariaDB - MySQL import and export format?

Sure, here are the steps on how to import and export databases using phpMyAdmin in your control...

Server Paths - PHP Perl Python and More

PHP/MariaDB/MySQL | Updated March 2026 The default path to PHP on Ultra Web Hosting servers...



Save 30% on web hosting - Use coupon code Hosting30