How to Connect to the MySQL Database? Print

  • Databases, cPanel
  • 37

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.

If you are not sure where your configuration file is, check at the bottom of this KB for the list of different scripts and their location in filesystem:

Database driven scripts, such as Wordpress, WHMCS and Joomla, will generally have a default configuration file ready for you to edit with the appropriate information. Below you will find examples of what this access information will look like:

Host Name = localhost (input localhost)
Database Name = cpanelUsername_databaseName
Database Username = cpanelUsername_databaseUsername
Database Password = yourSelectedPassword

WordPress Example

Username = yourUserName Database Name = wordpressDB
Database-Username = wpDBUser Database-User Password = cfgrt5%vb

 

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

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

/** MySQL database password */
define('DB_PASSWORD', 'cfgrt5%vb');

/** 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.


To connect to the MySQL server remotely


Allowing remote MySQL connections is often done to enable a program on your personal computer to access a database on the server.

If you are connecting from your home computer, you need a MySQL client like Navicat, phpMyAdmin, Workbench or Dreamweaver.

Tips and Tricks for Moving Databases

  • When you move databases to our servers, the database name and username may change. This change must be updated in your script code. (The database name and username is clearly displayed in cPanel, in the MySQL area)
  • On Shared servers, the database username cannot be changed to something without the cPanel username in it. This is to keep database names and usernames from conflicting with others on the server.

MySQL User Has No Privileges

Since the 11.25 update, we've noticed an occasional bug where adding an IP to the MySQL remote access list results in the corresponding MySQL user having no privileges.

In order to get the correct privileges added:

  1. Go to your MySQL Databases in cPanel.
  2. Re-add the user to each database by selecting the user and the database from the drop-down menus.
  3. Reassign the privileges.
  4. Click Add.

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

Location of Script Configuration Files

These paths are relative to the root of the script, not the account nor domain. So if it's a vBulletin forum, under /home/yourUsername/www/forum/, the configuration file would be in /home/yourUsername/www/forum/includes/config.php

4Images Gallery /config.php
B2 Evolution /conf/_basic_config.php
Boonex Dolphin /inc/header.inc.php
Concrete5 /site/config.php
Coppermine Photo Gallery /include/config.inc.php
Crafty Syntax Live Help /config.php
Cube Cart /includes/global.inc.php
dotProject /includes/config.php
Drupal /sites/default/settings.php
e107 /e107_config.php
FAQMasterFlex /faq_config.php
Gallery /config.php
Geeklog /db-config.php
/siteconfig.php
/lib-common.php
glfusion /private/db-config.php
Hotaru /hotaru_settings.php
Joomla /configuration.php
LiveSite \local\config\lib\content_center\ livesite_customer_src\etc\conf\livesite_customer\database.properties
LifeType /config/config.properties.php
Magento /app/etc/local.xml
Mambo /configuration.php
MODx /core/config/config.inc.php
Moodle /config.php
MyBB /inc/config.php
Noahs Classifieds /app/config.php
Nucleus /config.php
ocPortal /info.php
osCommerce /includes/configure.php
/admin/includes/configure.php
PHP-Nuke /config.php
phpBB /config.php
phpFormGenerator /index.php
/mysql.class.php
phpFreeChat (only if you have saved form input to a database)
/forms/admin/config.inc.php
PHPlist /config/config.php
phpMyDirectory /defaults.php
phpWCMS /include/inc_conf/conf.inc.php
phpWebSite /conf/config.php
PhpWiki /admin.php
/lib/config.php
Pligg /libs/dbconnect.php
Post-Nuke /config.php
Saurus CMS /config.php
Siteframe /config.php
SMF /Settings.php
Soholaunch /sohoadmin/config/isp.conf.php
Textpattern /textpattern/config.php
Tiki /db/local.php
Trendy Site Builder (not applicable)
TYPO3 /typo3conf/localconf.php
vBulletin /includes/config.php
WebCalendar /includes/settings.php
WHMCS /configuration.php
WordPress /wp-config.php
X7 Chat /config.php
Xoops /mainfile.php
Zen Cart /includes/configure.php
/admin/includes/configure.php
Zikula /config.php

Was this answer helpful?

« Back