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.
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
- Database name - cPanel > MySQL Databases. Your databases are listed at the top
- Database user - same page, listed under "Current Users"
- 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
- Host - always
localhostfor 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.
- Go to cPanel > MySQL Databases
- Scroll to "Add User To Database"
- Select your user and your database from the dropdowns
- Click Add, then select ALL PRIVILEGES
- 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
johndoeand you create a database calledwordpress, the full database name isjohndoe_wordpress - If you create a user called
wpuser, the full username isjohndoe_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.
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):
- Go to cPanel > Remote MySQL
- Add the IP address of the computer that needs access
- Use your server hostname (from your welcome email) as the host, not
localhost - 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 TicketQuick Recap
- Check config file credentials - DB name, user, password, and host must all match cPanel
- Add user to database - creating them separately is not enough
- Host is always
localhost- for same-server connections - Use full prefixed names -
username_dbname, not justdbname - 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
