How to connect to a MySQL Database

Follow

How to Connect to the MySQL Database

In order for your MySQL database to work as intended, it will need a script calling or querying the database for the information it stores.

In order to do this, you must connect your script to the database with a configuration file.

The Configuration file location will vary depending on the script, and it would be wise to check your scripts documentation for confirmation.

NOTE: You may also use "Softaculous Script Installer" to automatically configure a site, and databases if you're unsure of the steps below.

Configuration Settings

Database driven PHP scripts, such as Wordpress, WHMCS and Joomla, will generally have a default configuration file ready for you to edit with the appropriate information. Wordpress for example uses "wp-config.php", and Joomla uses "configuration.php".

Below you will find examples of what this access information will look like:

Host Name = localhost
Database Name = cpanelUsername_databaseName
Database Username = cpanelUsername_databaseUsername
Database Password = your generated password when you created the database

WordPress Example

Username = username Database Name = dbname1
Database-Username = dbuser1 Database-User Password = RandomPassword123^

 

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

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

/** MySQL database password */
define('DB_PASSWORD', 'RandomPassword123^');

/** MySQL hostname */
define('DB_HOST', 'localhost');

While it is possible to connect to the database using your cPanel username and password, we NEVER recommend this.
Every time you change or reset your cPanel password your databases will stop working until configuration files are updated.
It is also a large security risk, as if your Scripts fall out of date and are exploited, that will allow an attacker complete access to your control panel, and all configuration!
Have more questions? Submit a request

Comments

Powered by Zendesk