1. Home
  2. MySQL Tutorials
  3. MySQL Create Database

MySQL Create Database

In this tutorial, We are going to cover, How to create database in MySQL using command line.

Database is created with the use of a unique MySQL Statement- CREATE DATABASE

Syntax:

CREATE DATABASE databasename;

Example:

Login to MySQL Database with UserName and Password using below command.

mysql> mysql -u mysqladmin -p

In this example, Let’s name the database “FOSS”

mysql> CREATE DATABASE FOSS;

Often, the CREATE DATABASE statement results in an error. This occurs when a database is already available. To remedy a situation like this, an option known as IF NOT EXISTS, should be used with the CREATE DATABASE statement.

mysql> CREATE DATABASE IF NOT EXISTS FOSS;

Use SHOW DATABASES statement to confirm above database is created and also to list all database in MySQL.

mysql> SHOW DATABASES;

Output:

mysql> SHOW DATABASES;

+--------------------+
| Database               |
+--------------------+
| information_schema   |
| FOSS                               |
| mysql                              |
| performance_schema |
+--------------------+

4 rows in set (0.02 sec)

Here, We have performed MySQL Create Database

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.