In MySQL, The CREATE DATABASE statement is used to create a new database.
CREATE DATABASE [IF NOT EXISTS] database_name [CHARACTER SET charset_name] [COLLATE collation_name];
CREATE DATABASE: This is the beginning of the statement and indicates that we want to create a new database.
IF NOT EXISTS: This is an optional clause. If specified, it prevents an error from occurring if the database with the specified name already exists. If the database exists, it will not be created again.
database_name: This is the name we give to our new database. It should follow the rules for naming conventions, such as not using spaces or special characters.
CHARACTER SET charset_name: This is an optional clause that allows you to specify the default character set for the new database. The character set defines the encoding for storing character data in the database.
COLLATE collation_name: This is an optional clause that allows you to specify the default collation for the new database. The collation defines the rules for comparing and sorting character data.
CREATE DATABASE IF NOT EXISTS your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
This example creates a new database named mydatabase with the UTF-8 character set and the utf8mb4_unicode_ci collation.
Note: After creating the database, we may want to switch to it to perform operations within that database. You can use the USE statement for that:
USE your_database_name;
After switching to the database, we can start creating tables, defining relationships, and performing various data operations within the context of the specified database.