When connecting a website to a MySQL database, the correct database hostname depends on the server your hosting account is using.
Some hosting servers run MySQL locally, while others use a separate dedicated database server. Because of this, the hostname may be:
-
localhost -
Your hosting server hostname
-
A dedicated MySQL server hostname
Always use the database hostname provided in your hosting welcome email or account information. If you are unsure, contact support and we can confirm the correct hostname for your server.
Common MySQL Connection Settings
Most website applications will ask for the following database details:
Database Host: The MySQL hostname assigned to your server
Database Name: Your full cPanel database name
Database User: Your full cPanel database username
Database Password: The password assigned to the database user
Database Port: Usually 3306 unless otherwise specified
Your database name and username normally include your cPanel username as a prefix.
For example:
Database Name: accountname_wordpress
Database User: accountname_wpuser
You can create and manage databases from:
cPanel > MySQL Databases
You can also use the MySQL Database Wizard to create a database, create a database user, and assign the correct permissions.
Why the MySQL Hostname Can Be Different
The database hostname depends on how the hosting server is configured.
On some servers, MySQL runs directly on the same server as your website. In this configuration, the hostname is usually:
localhost
Other servers use a dedicated MySQL server separate from the web server. This allows database workloads to run independently from website, PHP, email, and other hosting services.
On these servers, you will use the hostname provided for that server instead of localhost.
For example:
host-la-157.hudsonhost.com
Do not assume that localhost, your domain name, or another server hostname will work. Always use the hostname assigned to your hosting server.
Creating a MySQL Database
Setting up a MySQL database is easy once you are familiar with the process.
-
Log in to your control panel and open MySQL Databases.
-
Create a new MySQL database.
-
Create a MySQL user.
-
Add the MySQL user to the database.
-
Grant the user the required permissions, usually All Privileges.
Your database is now ready to use.
You will need the following information to connect your website or application:
-
Database hostname
-
Database name
-
Database username
-
Database password
If you do not know your database hostname, check your hosting welcome email or contact support. The correct hostname can vary depending on which server hosts your account.
Remote MySQL Access
Whether remote MySQL connections are available also depends on your hosting service and server configuration.
A normal website hosted inside your cPanel account can connect to its database using the assigned database hostname without requiring you to configure remote access.
A true remote MySQL connection is different. This is when another computer, server, application, or external service connects directly to MySQL.
Examples include:
-
Desktop database applications
-
Development computers
-
External web servers
-
Business intelligence software
-
Remote reporting systems
-
Database synchronization tools
-
Multi-server applications
If your hosting plan supports remote MySQL, access should only be permitted from trusted IP addresses.
Opening MySQL port 3306 to every public IP address is strongly discouraged.
Managing Databases Through cPanel
You can manage MySQL databases securely through phpMyAdmin.
phpMyAdmin allows you to:
-
Browse database tables
-
Import and export databases
-
Run SQL queries
-
Edit database records
-
Repair and optimize tables
-
Review database structure
You can access it from:
cPanel > phpMyAdmin
Troubleshooting MySQL Connection Errors
If your website cannot connect to MySQL, verify the following:
-
The database hostname is correct for your server.
-
The database name is entered correctly.
-
The database username includes the cPanel prefix when required.
-
The database password is correct.
-
The database user has been assigned to the database.
-
The database user has the required permissions.
-
The application configuration file contains the correct credentials.
A common mistake is creating a database and user without assigning the user to the database.
In cPanel, open MySQL Databases, locate Add User to Database, select the correct database and user, and grant the required privileges.
WordPress MySQL Configuration
WordPress stores its database connection settings inside the wp-config.php file.
A typical configuration may look like this:
define('DB_NAME', 'accountname_wordpress');
define('DB_USER', 'accountname_wpuser');
define('DB_PASSWORD', 'your-database-password');
define('DB_HOST', 'host-la-157.hudsonhost.com');
On a server where MySQL runs locally, the DB_HOST value may instead be:
define('DB_HOST', 'localhost');
The important part is to use the database hostname assigned to the server hosting your account.
Do not guess the hostname based on your domain name or server IP address. Check your welcome email or contact support if you are unsure.
Need Help Connecting?
If you are having trouble connecting your website or application to MySQL, submit a support ticket with the domain name and hosting account involved.
We can confirm the correct database hostname for your server and help verify your connection settings.