1. Knowledge Base
  2. >
  3. Results
  4. >
  5. How to Connect to the MySQL Database

How to Connect to the MySQL Database

 

For the MySQL database to work as intended, you will need a script calling or querying the database for the information it stores. To accomplish this, you must connect your script to the database with a configuration file.

Please check out this article to know where to locate your configuration file:

Are you looking for instructions on how to connect to MySQL remotely? If so, please visit the article, How to Connect to MySQL Remotely, for instructions.


What Are My Database Configuration Settings?

Platforms like WordPress, WHMCS, and Joomla usually have a default configuration file ready for you to edit with the appropriate information.

Hostname = localhost
Database name = cpanelUsername_databaseName
Database username = cpanelUsername_databaseUsername
Database password = the one you used when you created your username

In the sample settings below, we will use the configuration file format of WordPress.

cPanel username = example
Hostname = localhost
Database name = testdb
Database username = snappyuser
Database password = 0PXwMLtq%Xbt

// ** MySQL Settings ** //
/** The name of the database for WordPress */
define('DB_NAME', 'example_testdb');

/** MySQL database username */
define('DB_USER', 'example_snappyuser');

/** MySQL database password */
define('DB_PASSWORD', '0PXwMLtq%Xbt');

/** MySQL hostname */
define('DB_HOST', 'localhost');
It is possible to connect to the database using your cPanel username and password. However, we NEVER recommend this. Every time you change or reset your cPanel password, your databases will stop working until you update your configuration files again.
  • When moving databases to our servers, the database name and username may change. This change must be updated in your scripts.
  • On Shared servers, the database username cannot be changed without the cPanel username in it. This is to prevent database names and usernames from conflicting with others on the same server.

    In order to get the correct privileges added, please reassign your database user's privileges in cPanel. How To Assign Privileges to Database User
MySQL User Has No Privileges

We have noticed an occasional bug wherein adding an IP address to the MySQL remote access list results in the corresponding MySQL user having no privileges since the 11.25 update.

We have already notified cPanel about the issue in hopes of this bug being corrected in newer updates.