Everything in MySQL starts with a database — the container that holds your tables, views, and procedures. Creating one takes a single command, but a few best practices will save you headaches later.
Key Points
- Basic syntax: CREATE DATABASE sales_db;
- Avoid errors on re-runs: CREATE DATABASE IF NOT EXISTS sales_db;
- Set encoding: CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci for full Unicode support
- Switch to it with USE sales_db; before creating tables
- List all databases with SHOW DATABASES;
- Use lowercase names with underscores (sales_db, not SalesDB) for portability
.png)