25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Limited Inventory: High-Performance AMD-Powered Servers Now Available.* Shop Now >
Dedicated Hosting Deals | From $99/moShop Now
Earn hosting credits and a chance to win an Amazon gift card when you refer friends to Liquid Web!Read our promo rules

Create a MySQL Database on Linux via Command Line

Posted on by Ronald Caldwell | Updated:
Reading Time: 2 minutes

While the are many ways to create databases, system administrators benefit from knowing how to create a MySQL database in Linux via the command line. Knowing more than one way to accomplish a task provides flexibility in case the usual way you perform it is not an option. Use this tutorial to create a MySQL database via the command line.


  • Server running CentOS or AlmaLinux.
  • Root-level access to the server.
Create a MySQL Database on Linux via Command Line

Create MySQL Database on Linux using Command Line

Step 1:

Log into the MySQL server from the command line with the following command, specifying the user root with the -u flag, and prompt for a password using the -p flag. Enter your current password once prompted to complete the login.

mysql -u root -p

You can change the MySQL password for the root user or any other user in the database via the command line.

A prompt displays like the one below once you log in.


Step 2:

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, the system will not create a new database, and you will receive this error.

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

You can avoid this error by using the following command. It only creates the database tutorial_database if a database of that name does not already exist.


View All MySQL Databases

Use the following command to view the database you've created.


Here is the resulting output.

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

Wrapping Up

Creating a MySQL database from the Linux command line is an easy process. System administrators would do well to have this process in their toolkit to add flexibility to their workflow.

Are you looking for a server solution that includes MySQL out of the box? Liquid Web offers VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers with the LAMP stack built in. Contact our sales team today to start or migrate your project.

Series Navigation
<< Previous ArticleNext Article >>
Avatar for Ronald Caldwell

About the Author: Ronald Caldwell

Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.

Latest Articles

How to Edit the PHP Memory for Your WordPress Site via WP Toolkit

Read Article

What is CGI-Bin and What Does it Do?

Read Article

Top 10 Password Security Standards

Read Article

Top 10 Password Security Standards

Read Article

How to Use the WP Toolkit to Secure and Update WordPress

Read Article