How to Create a MySQL Database

MySQL databases are essential for dynamic websites, content management systems like WordPress, and web applications. This guide walks you through creating a database, setting up a user, and connecting everything in cPanel.

MySQL database creation flow in cPanel

Step 1: Create a New Database

  1. Log in to your cPanel dashboard.
  2. Scroll to the Databases section and click MySQL Databases.
  3. Under Create New Database, enter a name for your database. cPanel will automatically prepend your account prefix (e.g., youruser_mydatabase).
  4. Click Create Database.
  5. Click Go Back to return to the MySQL Databases page.

Step 2: Create a Database User

A database user is required to interact with your database. Never use the root account for application connections.

  1. On the same MySQL Databases page, scroll down to MySQL Users > Add New User.
  2. Enter a username and a strong password. Use the password generator if needed.
  3. Click Create User.
  4. Click Go Back to return to the page.

Step 3: Assign the User to the Database

Creating a user and a database does not automatically link them. You must assign the user with specific privileges.

  1. Scroll to the Add User To Database section.
  2. Select the user you just created from the User dropdown.
  3. Select the database you created from the Database dropdown.
  4. Click Add.
  5. On the privileges screen, check ALL PRIVILEGES if this user needs full access (recommended for CMS installations like WordPress). For more restrictive access, select only the specific privileges your application requires.
  6. Click Make Changes.

Connecting to Your Database from PHP

Use the following connection details in your application or CMS configuration file:

$host = 'localhost';
$dbname = 'youruser_mydatabase';
$dbuser = 'youruser_mydbuser';
$dbpass = 'your_password_here';

For WordPress, these values go into the wp-config.php file:

define('DB_NAME', 'youruser_mydatabase');
define('DB_USER', 'youruser_mydbuser');
define('DB_PASSWORD', 'your_password_here');
define('DB_HOST', 'localhost');

Using phpMyAdmin

cPanel includes phpMyAdmin, a web-based tool for managing your databases visually.

  1. In cPanel, click phpMyAdmin under the Databases section.
  2. Select your database from the left sidebar.
  3. From here, you can browse tables, run SQL queries, import or export data, and manage your database structure.

Tips and Best Practices

  • Use unique passwords for each database user. Do not reuse your cPanel password.
  • Back up your database regularly using phpMyAdmin's Export feature or the cPanel Backup Wizard.
  • Delete unused databases and users to keep your account tidy and secure.
  • Note the full names including your cPanel prefix when entering credentials into configuration files. Forgetting the prefix is one of the most common connection errors.

If you run into connection errors, verify that the correct user is assigned to the correct database and that all privileges are granted. For further assistance, contact CyclebreezeHost support.