MySQL CREATE DATABASE

A database is the container for your tables. The CREATE DATABASE statement makes a new one.

CREATE DATABASE school;
MySQL says

Query OK, 1 row affected (0.01 sec)


IF NOT EXISTS

If the database already exists, the command above gives an error. Add IF NOT EXISTS to skip the error.

CREATE DATABASE IF NOT EXISTS school;

Set the character set

Use utf8mb4 so that the database can store all languages and emojis.

CREATE DATABASE school
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

Check that it was created

SHOW DATABASES;
Result (your list can be different)
Database
information_schema
mysql
performance_schema
school
sys

Note: Database names are case-sensitive on Linux servers, but not on Windows. Use small letters with underscores, like my_shop, and avoid spaces.

Summary


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a query to get all column names of a database table
Write a query to create a new table with the data and structure of another table
Interview Questions & Answers
Write a query to create a new table which consists of data and structure copied from the other table
What is a primary key in MySQL?
What is a foreign key in MySQL?
What is the difference between CHAR and VARCHAR in MySQL?
What is normalization in MySQL?
What is AUTO_INCREMENT in MySQL?
What is the difference between primary key and unique key?