How to Create a MySQL Database Using CLI & cPanel

Learn How to Create a MySQL Database Using CLI & cPanel

If you need to create a database for your website there are multiple ways to do it. In this guide, you can learn how to create a MySQL database using the command line interface (CLI) and from cPanel. You can then being using the database or connect your software.

Create a MySQL Database Using CLI

If you are running a Linux server with MySQL but no cPanel, you can simply use the terminal to create a MySQL database, database user, and password, as well as, assign all privileges to the user for the database.

Don’t have time to read the article? Watch our walk-through video.

IMPORTANT: This guide is intended for use with our Cloud Server Hosting and other hosting plans that do not include cPanel. If your server includes cPanel, you should follow our guide on How to Create a MySQL Database Using the cPanel API.

  1. SSH into your server as root.
  2. Log into MySQL as root:
    mysql -u root
  3. Create a new database user:
    GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' IDENTIFIED BY '[email protected]$w0rd123!';
  4. Log out of MySQL by typing: \q.
  5. Log in as the new database user you just created:
    mysql -u db_user -p
  6. Then, type the new database user’s password and press Enter.
    Create a Database in the Command Line Interface (CLI)
  7. Create a new database:

    CREATE DATABASE db_name;

How to Create a MySQL Database in cPanel

Don’t have time to read the full guide? Watch our walk-through video.

When you create a database, many users are unaware that there are several other tasks that you need to do as well. The new database creation process actually involves:

  1. Creating a database
  2. Creating a database user
  3. Giving your database user access to work with your database

Luckily for us, cPanel includes a MySQL Database Wizard that walks you through each of these steps.

Creating a Database in cPanel Using the MySQL Database Wizard

  1. Log into your cPanel.
  2. Click the MySQL Database Wizard under the Databases heading.
    Accessing the MySQL Database Wizard
  3. Next to New Database enter a name for your database and click Next Step.
    Entering a Database Name
  4. Enter a username, enter a password twice, then click the Create User button.
    Creating a Database User
  5. On the next page, you’ll assign privileges for the user to the database. Check the box next to All Privileges and then click Next Step. You can also select specific privileges instead.
    Providing Privileges to the Database User

    You are finished when you see a message stating that the user was added to the database.
    User Was Added to the Database

Congratulations! Now, you know how to create a MySQL database from the command line and using cPanel. Want to learn more about database management? Check out official MySQL documentation or our guide on How to Import MySQL Databases in Command Line.

If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.

check markCentOS, Debian, or Ubuntu check markNo Bloatware check markSSH and Root Access

John-Paul Briones Content Writer II

John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

More Articles by John-Paul

Thoughts on “How to Create a MySQL Database Using CLI & cPanel

Was this article helpful? Let us know!