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.
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 WordPress's database PHP connection strings settings (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');
- 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. This prevents 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. For the instructions, please check out the article, 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, hoping this bug will be corrected in newer updates.