Skip to main content

How to Connect to Your MySQL Database

This guide shows you how to connect database-driven applications such as WordPress, WHMCS, and Joomla to a MySQL database. You’ll need to add your MySQL database details to the application's configuration file.

Before You Start

You will need:

  • A MySQL database created in cPanel.

  • A MySQL database user.

  • The database user's password.

  • Access to your application's configuration file.

If you need to create a MySQL database first, see our guide to creating a MySQL database.

1. Find Your Database Details

Use the following details when configuring your application:

  • Hostname: localhost

  • Database Name: The database you created in cPanel → MySQL Databases

  • Database User: The user you created in cPanel → MySQL Databases

  • Database Password: The password you created for the database user

💡 Tip: Make sure the database user has been added to the database and has the required permissions.

2. Add the Details to Your Configuration File

The exact configuration file depends on the application you are using.

For example, WordPress uses a file called wp-config.php.

Example

Your database details might be:

  • Database Name: joe1337_wrdp1

  • Database User: joe1337_wp1

  • Database Password: eHTb7%Pxa9

  • Database Host: localhost

In wp-config.php, the settings would look like this:

define('DB_NAME', 'joe1337_wrdp1'); define('DB_USER', 'joe1337_wp1'); define('DB_PASSWORD', 'eHTb7%Pxa9'); define('DB_HOST', 'localhost');

Replace the example values with your own database details.

⚠️ Important

We do not recommend using your cPanel username and password for your application's database connection.

If you change or reset your cPanel password, your application may lose access to the database until its configuration is updated.

Using a separate database user makes it easier to manage your database connection and credentials.

3. Check the Connection

After adding your database details:

  1. Save the configuration file.

  2. Open your website or application.

  3. Check that it loads correctly.

  4. If you receive a database connection error, verify the database name, username, password, and hostname.

Result

Your application is now configured to connect to your MySQL database using the database credentials in its configuration file.

Did this answer your question?