MySQL — Create Database
Basic CREATE DATABASE
CREATE DATABASE mydb;
CREATE DATABASE IF NOT EXISTS
CREATE DATABASE IF NOT EXISTS mydb;
With Character Set
CREATE DATABASE mydb
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
With Comment
CREATE DATABASE mydb
COMMENT 'My application database';
Examples
-- Create e-commerce database
CREATE DATABASE ecommerce
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
-- Create blog database
CREATE DATABASE IF NOT EXISTS blog;
-- Create multiple databases
CREATE DATABASE IF NOT EXISTS shop;
CREATE DATABASE IF NOT EXISTS forum;
CREATE DATABASE IF NOT EXISTS gallery;
-- Show created databases
SHOW DATABASES;
Mini Practice
Write MySQL code that:
- Creates a basic database
- Creates a database if not exists
- Creates with character set
- Creates multiple databases
Up Next
Next: Learn about Dropping Databases.
Related Topics
Frequently Asked Questions about Create Database
What is Create Database in MySQL?
Create Database is a fundamental concept in MySQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Create Database?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Create Database.
Why is Create Database important in MySQL?
Create Database is essential for MySQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.