iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

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

DBCommand
MySQL / MariaDBSHOW DATABASES;
PostgreSQL\l in psql, or SELECT datname FROM pg_database;
SQL ServerSELECT 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

Example
CREATE DATABASE shop;
Try it Yourself »

Exercise

Make the DB creation script safe to re-run.

CREATE DATABASE NOT EXISTS shop;

Test yourself

Q1. In MySQL 2026 the recommended character set is…
Q2. Make the script re-runnable with…
Q3. Production schema changes should go through…

Discussion

Loading…