How to create a database in cPanel?


For many modern websites, especially those built with content management systems like WordPress, a database is a fundamental component. It's where all your website's dynamic content – posts, pages, user information, settings, and more – is stored and organised.

This guide will walk you through the complete process of creating a MySQL database in cPanel, including setting up a dedicated user and assigning the necessary privileges. This ensures your website has a secure and functional database to operate with.


What You'll Need:

Before you begin, make sure you have the following:

  • Access to your cPanel account via your EncodeDotHost customer portal.
  • A chosen name for your new database (e.g., mywebsite_db).
  • A chosen username for your database (e.g., mywebsite_user).
  • A strong, secure password for your database user.

Step 1: Create the New Database

Your first step is to create the database itself within cPanel.

  1. Log in to your cPanel account.
  2. In the "Databases" section, click on the "MySQL Databases" icon. You'll see an icon that typically looks like a database cylinder.
    MySQL Databases icon in cPanel
  3. Under the "Create New Database" section, enter a name for your new database in the "New Database:" field.
    Create Database input field
    • Note: cPanel automatically prefixes your database name with your cPanel username and an underscore (e.g., if your cPanel username is exampleuser and you enter mydb, the full database name will be exampleuser_mydb).
  4. Click the "Create Database" button.
    Success message after database creation
  5. You will see a success message confirming the database has been added. Click "Go Back".

Step 2: Create a New Database User

For security and functionality, it's essential to create a dedicated user for your database. You should never use your cPanel login details for database access.

  1. On the same "MySQL Databases" page, scroll down to the "MySQL Users" section.
  2. Under "Add New User", enter a Username for your database user.
    • Note: Similar to databases, cPanel will prefix your username (e.g., exampleuser_myuser).
  3. Enter a strong password in the "Password" field and re-enter it in the "Password (Again)" field. We highly recommend using the "Password Generator" for a secure password.
  4. Click the "Create User" button.
  5. You will see a success message. Click "Go Back".

Step 3: Add the User to the Database and Assign Privileges

Now you need to connect your newly created database and user, granting the user permissions to access and manage the database.

  1. On the "MySQL Databases" page, scroll down to the "Add User To Database" section.
  2. From the "User" dropdown menu, select the database user you just created (e.g., exampleuser_myuser).
  3. From the "Database" dropdown menu, select the database you created in Step 1 (e.g., exampleuser_mydb).
  4. Click the "Add" button.
  5. On the next screen, "Manage User Privileges", check the box next to "ALL PRIVILEGES". This grants the user full control over the database, which is typically required for most web applications.
  6. Click the "Make Changes" button.
  7. You will see a success message confirming the privileges have been saved.

Step 4: Note Down Your Database Details

It's crucial to record these details securely, as your website application (e.g., WordPress) will need them to connect to the database.

  • Database Name: (e.g., exampleuser_mydb)
  • Database Username: (e.g., exampleuser_myuser)
  • Database Password: (the strong password you generated/set in Step 2)
  • Database Host: This is almost always localhost.

Security Tip: Never share your database credentials publicly or embed them directly in client-side code. Always store them in secure configuration files on your server.


Troubleshooting Tips:

  • "Error creating database/user": Double-check for typos or if a database/user with that name already exists.
  • Website connection issues: If your website can't connect to the database, ensure the database name, username, and password in your website's configuration file (e.g., wp-config.php for WordPress) exactly match the details you noted down. Also, confirm the database host is localhost.
  • Password strength: Always use a strong, unique password. Weak passwords can lead to security vulnerabilities.
  • Still having trouble? Contact EncodeDotHost support with details of the issue and any error messages you're receiving, and they'll be happy to assist further.

By following these steps, you've successfully created and configured a MySQL database and user in cPanel, ready for your website application to use!


Was this answer helpful?

One email a month. Endless business benefits.

Don't miss out on WMTWWFY — the newsletter that keeps your website fast, safe, and visible.

« Back
Spinner
aluminium-anthropoid Security Check