Skip to the content.

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:

Use cases:

2. Sakila Database (Coming Soon)

A DVD rental database (official MySQL sample database).

Tables:

Use cases:

3. World Database (Coming Soon)

Geographical data about countries, cities, and languages.

Tables:

Use cases:

How to Import Sample Databases

Method 1: Using phpMyAdmin

  1. Open phpMyAdmin
  2. Create new database
  3. Click “Import” tab
  4. Choose .sql file
  5. 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

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

  1. Sakila: https://dev.mysql.com/doc/sakila/en/
  2. World: https://dev.mysql.com/doc/world-setup/en/
  3. Employees: https://github.com/datacharmer/test_db

Installation Instructions

Follow the instructions provided with each database for installation.

Practice Queries

Each sample database includes:

Contributing

Have a great sample database to share? See CONTRIBUTING.md for guidelines.

Additional Resources