SQL CREATE DATABASE
CREATE DATABASE makes a new, empty database. You'll usually run it once per project from a SQL client or a deployment script.
Basic form
SQL
CREATE DATABASE shop;
Specifying character set and collation
SQL
-- MySQL — pick utf8mb4 in 2026, never plain utf8 CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Why utf8mb4? Plain utf8 in MySQL is a 3-byte subset that can't store 4-byte characters like emoji.
If not exists
Make the script re-runnable:
SQL
CREATE DATABASE IF NOT EXISTS shop;
Permissions
CREATE DATABASE is a privileged operation. Production roles typically can't run it — that's reserved for the DBA or migration tool. Application users get SELECT/INSERT/UPDATE/DELETE only.
Listing databases
| DB | Command |
|---|---|
| MySQL / MariaDB | SHOW DATABASES; |
| PostgreSQL | \l in psql, or SELECT datname FROM pg_database; |
| SQL Server | SELECT name FROM sys.databases; |
Tip: Don't put production schema changes inside ad-hoc
CREATE DATABASE scripts. Use a migration tool (Laravel migrations, Flyway, Liquibase) so every environment ends up the same.Example
Exercise
Make the DB creation script safe to re-run.
CREATE DATABASE
NOT EXISTS shop;
Two letters; pairs with NOT EXISTS.
Discussion
Loading…