Create a MySQL Database on Linux via Command Line

Posted on by Justin Palmer | Updated:
Reading Time: 2 minutes

Preflight Check

Create a MySQL Database

Create a MySQL Database on Linux via Command Line

First we'll log in to the MySQL server from the command line with the following command:

mysql -u root -p

In this case, I've specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.

If you need to change your root (or any other) password in the database, then follow this tutorial on changing a password for MySQL via the command line.

You should now be at a MySQL prompt that looks very similar to this:


To create a database with the name tutorial_database type the following command:

CREATE DATABASE tutorial_database;

If a database of the same name already exists, then a new database will not be created and you'll receive this error:

ERROR 1007 (HY000): Can't create database 'tutorial_database'; database exists

To avoid seeing this error use the following command instead:


The above command will only create the database tutorial_database if a database of that name does not already exist.

View All MySQL Databases

To view the database you've created simply issue the following command:


Your result should be similar to this:

| Database           |
| information_schema |
| mysql              |
| test               |
| tutorial_database  |
4 rows in set (0.00 sec)

When standard uptime is not enough, you don’t have to wage war alone. Liquid Web’s High-Availability Databases provides the bleeding edge hardware needed for keeping your site online. If using this type of setup significantly reduces overhead while not having to worry about managing MySQL sounds like a dream come true?  Then check out our affordable plans here!

Series Navigation
<< Previous ArticleNext Article >>
Avatar for Justin Palmer

About the Author: Justin Palmer

Justin Palmer is a professional application developer with Liquid Web

Latest Articles

How to Set Up Hotlink Protection in cPanel

Read Article

How to Set Up Hotlink Protection in cPanel

Read Article

What is the Difference Between NGINX and Apache?

Read Article

Accessing Man Pages on Ubuntu 16.04 LTS

Read Article

What is VMware Fusion?

Read Article