MySQL – Create Database
Database is a collection of tables that belong to or used by an application. Different users in an use case of application might access the tables of a database.
Multiple databases could be hosted in a single MySQL server, because of which a client has to select a database prior to requesting the SQL operations.
In this tutorial, we shall learn how to create a database and in the subsequent tutorials, we shall create tables in the database.
Syntax – Create a DATABASE in MySQL
Following is the syntax to create a database. Providing database name is mandatory.
CREATE DATABASE database_name;
Example 1 – Create DATABASE in MySQL
Following is example SQL query to create a database named students.
CREATE DATABASE students;
mysql> CREATE DATABASE students; Query OK, 1 row affected (0.03 sec)
When the above SQL Query is executed, a database named “students” is created.
To check if the database “students” is created or not , run the following SQL Query
SHOW DATABASES;
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | students | | sys | +--------------------+ 5 rows in set (0.02 sec)
“students” database has been successfully created. Other databases that appear in the list are default databases that come with MySQL Server.
Note : If you have come across SCHEMA in other database management systems, SCHEMA is a collection of tables and DATABASE is a collection of SCHEMAs. But in MySQL, there is nothing specifically a SCHEMA. Hence SCHEMA could be used as an alias to DATABASE.