BuycPanel Blog

BuycPanel Blog

Latest news and updates

12/16/2014 – Connect to MySQL with cPanel

Posted by Jamison on 16 12 2014.

For your MySQL database to work properly, you must be able to connect to MySQL. This requires a script to contact the database for the information it contains.


Note that not all script configuration files for everything is located in the same place. For instance the one for Joomla is in the /configuration.php path, the one for WordPress is at /wp-config.php while the one for Moodle is at /config.php


What to look out for? The access information should look like:


Host Name = localhost (literally input localhost)

Database Name = cpanelUsername_databaseName

Database Username = cpanelUsername_databaseUsername

Database Password = what your password is


Let’s say your username is John, the database Name is wrdp1, the database-Username is wp1 and the Database-User Password is pizza. Host name will always be localhost.


For WordPress, as an example, it should look like this:


// ** MySQL Settings ** //

/** The name of the database for WordPress */

define(‘DB_NAME’, ‘John_wrdp1’);


/** MySQL database username */

define(‘DB_USER’, ‘ John_wp1’);


/** MySQL database password */

define(‘DB_PASSWORD’, ‘pizza’);


/** MySQL hostname */

define(‘DB_HOST’, ‘localhost’);


Although you can connect to the database using your cPanel username and password, this is strongly discouraged. This is because whenever you change or reset your cPanel password your databases will stop working until the configuration files are updated.


If you are on a shared server, the database user name cannot be changed to something without the cPanel user’s name in it.


How to connect to MySQL Database remotely


All IPs are blocked from the MySQL database by default. You must add them to an access list so you can access the server. Before connecting to MySQL from another computer you must also be sure the connecting computer is enabled as an access host.


To do this you might need a MySQL client like Navicat, Dreamweaver, phpMyAdmin or Workbench. You also need to know ahead what your IP address is, if you don’t know then go to


Your configuration should look like this:


Host name = (use the server IP address)

Database name = (cpanelUsername_databaseName)

Database username = (cpanelUsername_databaseUsername)

Database password = (the password you entered for that database user)

MySQL Connection Port = (what number your connection port is)


  1. On your cPanel homescreen, click the Remote MySQL icon.
  2. Enter the IP address of the computer that will be making the remote connection in the field beside “Add Host”.
  3. Click the “Add Host” button. That’s it! You can now access your MySQL databases remotely.


Note that if you are connecting from an IP address that can change periodically you can use % as the wildcard value. However, this is not recommended as this will grant access from anywhere. You must also have to update the connecting IP to remotely access MySQL whenever it changes.


If you are using cPanel X3 the operation should still be the same. However, the cPanel X theme will have the MySQL Database icon in the Database section instead of the Remote MySQL icon. The operations is still pretty much the same, you just have to scroll down all the way to the bottom to get to the field where you have to input your IP address.