Loading...

Knowledge Base
Up to 75% off on hosting for WordPress websites and online stores

Connecting Scripts to MySQL Databases

Connecting Scripts to MySQL Databases is essential for accessing and managing data. This guide outlines the process of establishing connections using a configuration file to securely store your database credentials.

Configuration Settings for MySQL Database Connections

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 using a configuration file. If you are unsure where your configuration file is, check this list of different scripts to find its location: Location of Script Configuration Files.

Configuration Settings:

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:

  • Hostname = localhost (literally put localhost)
  • Database name = (cpanelUsername_databaseName)
  • Database username = (cpanelUsername_databaseUsername)
  • Database password = (whatever you picked)

WordPress Example:

Username = joe1337 , Database name = joe1337_wrdp1 , Database-user name = joe1337_wp1 , Database-user password = eHTb7%Pxa9

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

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

/** MySQL database password */
define('DB_PASSWORD', 'eHTb7%Pxa9');

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

Note: 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 can be found in the MySQL Databases tool under the Databases category of your cPanel.)

The database user name cannot be changed to something on shared servers without the cPanel user name. This is to keep database names and usernames from conflicting with other people on the server.

While someone can use their cPanel username and password to connect to the database, we NEVER recommend doing this because every time you change or reset your cPanel password, your databases will stop working and need their configuration files updated.

If you need to connect to your database remotely using an application, please see our related articles on Remote Database Connection Setup and Managing Your Database with Applications.

Summary

Connecting scripts to MySQL databases is fundamental to database driven websites. This connects the very scripts, whether in PHP, Python, or another language, to the database, allowing the reading and writing of information on to it, to store data, and even modify existing database information. This is commonly executed using a configuration file which sets out to store database credentials out of the script itself: hostname, user-name, password. It enhances security and makes it easier to administer the connections between the scripts and the databases. The link created by scripts may run SQL queries for executing different operations and makes possible user login, content administration, and electronic trade transactions. This paper provides the step-by-step guide and best practices for connecting scripts to MySQL databases in a safe manner.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

 
* Your feedback is too short

Loading...