The CREATE DATABASE statement creates a new database on the MySQL server. A database is a tl-container that holds tables, views, stored procedures, and other objects. You need the CREATE privilege to run this statement.
-- Basic syntax
CREATE DATABASE shop;
-- Avoid error if database already exists
CREATE DATABASE IF NOT EXISTS shop;
-- Create with explicit character set and collation (recommended)
CREATE DATABASE IF NOT EXISTS shop
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
-- List all databases on the server
SHOW DATABASES;
-- Select the database to use for subsequent queries
USE shop;
-- Confirm which database is currently active
SELECT DATABASE();
Always create databases with utf8mb4 character set and utf8mb4_unicode_ci collation. The older utf8 in MySQL is actually a 3-byte subset that cannot store emoji or some rare Unicode characters - utf8mb4 is the true 4-byte UTF-8 encoding.
utf8mb4 supports all Unicode characters including emoji).utf8mb4_unicode_ci is case-insensitive and accent-insensitive, following Unicode rules.-- Change the character set and collation of an existing database
ALTER DATABASE shop
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
-- Show the CREATE DATABASE statement (includes charset/collation)
SHOW CREATE DATABASE shop;
-- Drop a database (CAUTION: deletes all tables and data permanently)
DROP DATABASE shop;
-- Drop only if it exists (avoids error)
DROP DATABASE IF EXISTS shop;
_), and dollar signs ($).SELECT, TABLE) as database names - if you must, wrap them in backticks: `select`.my_shop, ecommerce_db.-- Full setup for the shop database used throughout this tutorial
CREATE DATABASE IF NOT EXISTS shop
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
USE shop;
-- Verify the database was created with correct settings
SHOW CREATE DATABASE shop\G
-- Check available character sets
SHOW CHARACTER SET LIKE 'utf8%';
-- Check available collations for utf8mb4
SHOW COLLATION WHERE Charset = 'utf8mb4' AND Collation LIKE '%unicode%';
Explore 500+ free tutorials across 20+ languages and frameworks.