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
No Content Found.
Interview Questions & Answers
No Content Found.