How to Create a MySQL Database Using the Command Line

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.

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

Create a MySQL Database Using CLI

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

  1. SSH into your server.
  2. Log into MySQL as the root user.
  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

    Then, type the new database user’s password and press Enter.

  6. Create a new database:
    CREATE DATABASE db_name;

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

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

Was this article helpful? Let us know!