Skip to main content

How do I connect to my MySQL?

This article explains how to connect database-driven scripts like WordPress to a MySQL database using the configuration file.

Updated over 3 weeks ago

โš™๏ธ Connect Database-Driven Scripts to Your MySQL Database

Database-driven systems like WordPress, WHMCS, and Joomla use a standard configuration file where you enter your database details. Below youโ€™ll find an example of how to set this up.

๐Ÿ“ Your Database Details

  • Hostname: 127.0.0.1 or localhost

  • Database Name: Created in cPanel โ†’ MySQL Databases

  • Database User: Created in cPanel โ†’ MySQL Databases

  • Database Password: The password you chose when creating the user

You can find your MySQL users and password using the following guide.

๐Ÿ“ WordPress Example

Hereโ€™s how a WordPress configuration might look:

Your details:

  • Username: joe1337

  • Database Name: wrdp1

  • Database User: wp1

  • Password: eHTb7%Pxa9

In wp-config.php:

// ** MySQL Settings ** // /** The name of the database for WordPress */ define('DB_NAME', 'joe1337_wrdp1'); /** MySQL database username */ define('DB_USER', 'joe1337_wp1'); /** MySQL database password */ define('DB_PASSWORD', 'eHTb7%Pxa9'); /** MySQL hostname */ define('DB_HOST', 'localhost');

โš ๏ธ Important!

While it is technically possible to connect using your cPanel username and password, we do not recommend it. Each time you change or reset your cPanel password, your databases will stop working until the configuration files are updated.

โœ… Done!

Now you know how to connect your scripts, such as WordPress, to your MySQL database via the configuration file.

Did this answer your question?