MySQL CREATE DATABASE Statement
MySQL CREATE DATABASE Statement
The CREATE DATABASE statement in MySQL is used to create a new database. It is one of the first steps when starting a new MySQL project.
๐น Syntax
-
database_nameโ Name of the database to create -
Database names must be unique on the MySQL server.
-
Optional clauses:
IF NOT EXISTSand character set/collation.
๐น Syntax with IF NOT EXISTS
-
Prevents an error if the database already exists.
๐น Syntax with Character Set and Collation
-
CHARACTER SETโ Sets the default character set for the database. -
COLLATEโ Sets the default collation (sorting rules).
๐น Example 1: Simple Database Creation
-
Creates a new database called
SchoolDB.
๐น Example 2: Create Database If Not Exists
-
Ensures the command doesnโt fail if
SchoolDBalready exists.
๐น Example 3: Create Database with UTF8 Character Set
-
Sets database to support Unicode characters.
๐น Key Points
-
Database names should be descriptive and unique.
-
Use IF NOT EXISTS to avoid errors if the database already exists.
-
Specify CHARACTER SET and COLLATE for multi-language support.
-
After creating a database, use:
