Sample Databases
Overview
This directory contains sample databases for practicing and learning MySQL.
Available Sample Databases
1. Employees Database (Coming Soon)
A comprehensive database with departments, employees, titles, and salaries.
Tables:
- employees
- departments
- dept_emp
- dept_manager
- titles
- salaries
Use cases:
- Complex JOINs
- Aggregate functions
- Date operations
- Performance optimization
2. Sakila Database (Coming Soon)
A DVD rental database (official MySQL sample database).
Tables:
- film
- actor
- customer
- rental
- payment
- store
- And more…
Use cases:
- Many-to-many relationships
- Full-text search
- Views and triggers
- Stored procedures
3. World Database (Coming Soon)
Geographical data about countries, cities, and languages.
Tables:
- country
- city
- countrylanguage
Use cases:
- Simple queries
- Grouping and aggregation
- Filtering
- Sorting
How to Import Sample Databases
Method 1: Using phpMyAdmin
- Open phpMyAdmin
- Create new database
- Click “Import” tab
- Choose .sql file
- Click “Go”
Method 2: Using Command Line
# Create database
mysql -u root -p -e "CREATE DATABASE sample_db;"
# Import SQL file
mysql -u root -p sample_db < sample_database.sql
Method 3: Using WAMP/XAMPP Shell
WAMP:
cd C:\wamp64\bin\mysql\mysql[version]\bin
mysql -u root -p sample_db < C:\path\to\sample_database.sql
XAMPP:
cd C:\xampp\mysql\bin
mysql -u root -p sample_db < C:\path\to\sample_database.sql
Creating Your Own Sample Data
Using Online Generators
- Mockaroo - Generate realistic test data
- Generatedata - Random data generator
- SQL Generator - SQL INSERT generator
Using MySQL Functions
-- Create sample users
INSERT INTO users (username, email, created_at)
SELECT
CONCAT('user', num),
CONCAT('user', num, '@example.com'),
DATE_SUB(NOW(), INTERVAL FLOOR(RAND() * 365) DAY)
FROM (
SELECT @row := @row + 1 AS num
FROM information_schema.TABLES t1,
information_schema.TABLES t2,
(SELECT @row := 0) r
LIMIT 1000
) AS numbers;
Official MySQL Sample Databases
Download Locations
- Sakila: https://dev.mysql.com/doc/sakila/en/
- World: https://dev.mysql.com/doc/world-setup/en/
- Employees: https://github.com/datacharmer/test_db
Installation Instructions
Follow the instructions provided with each database for installation.
Practice Queries
Each sample database includes:
- Schema documentation
- Sample queries
- Practice exercises
- Solutions
Contributing
Have a great sample database to share? See CONTRIBUTING.md for guidelines.