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. You must connect your script to the database with a configuration file to accomplish this.

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.


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 below, we will use the database settings of WordPress (file format of wp-config.php).

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');
Note: 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.
  • The database name and username may change when moving databases to our servers. This change must be updated in your scripts.
  • On Shared hosting, 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.
  • To get the correct privileges added, please reassign your database user's privileges in cPanel. Please check out the article, How To Assign Privileges to Database User for the instructions.

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.