MySQL sample databases for practice
MySQL is the open-source database behind many websites, including WordPress. Its SQL is close to standard, with a few differences in functions, booleans and text comparison. Here are 13 practice databases as MySQL scripts, each with six questions whose answers were produced by MySQL 8.4.13.
Sales orders
Superstore-style retail orders with sales, cost, discount and profit.
MySQLOnline store
Four related tables (customers, products, orders, order items) for JOIN practice.
MySQLEmployees
An HR table: departments, titles, hire dates, salaries and managers.
MySQLCustomers
A customer list with segments, order counts, lifetime spend and activity.
MySQLInventory
Stock levels, reorder points and stock value across four warehouses.
MySQLStudent grades
Test scores, averages, letter grades and attendance for grades 9-12.
MySQLWebsite traffic
Daily sessions, users, bounce rate and conversions by channel.
MySQLMarketing campaigns
Budget, spend, impressions, clicks, CPA and ROAS per campaign.
MySQLCall center
Calls with queue, reason, wait and handle time, resolution and CSAT.
MySQLRestaurant orders
Order lines with menu items, tickets, order type and payment.
MySQLInvoices
Invoices with due dates, payment dates, tax, status and days late.
MySQLBank transactions
One fictional account: debits, credits, categories and a running balance.
MySQLMessy customers
A customer list with duplicates, blanks, mixed dates and text in number columns.
MySQL SQL in these exercises
The questions are the same on every engine; what changes is the syntax. These are the MySQL-specific parts you will meet:
- DATE_FORMAT(date, '%Y-%m') formats a date as year-month text.
- YEAR(date) returns the year as a number.
- DATEDIFF(later, earlier) returns the number of days between two dates.
- LIMIT n at the end returns the first n rows.
- BOOLEAN is stored as TINYINT(1): TRUE is 1 and FALSE is 0.
- CONCAT(a, b, ...) joins strings; || is not string concatenation by default.
- SUBSTRING(text, start, length) cuts out part of a string.
- 1.0 * a / b gives a decimal result.
- The cast to DECIMAL keeps the average exact before rounding.
- Window functions need MySQL 8.0 or later.
- CHAR_LENGTH counts characters (LENGTH counts bytes).
- The default utf8mb4 collation ignores case, so COUNT(DISTINCT email) would already merge upper- and lower-case copies; COLLATE utf8mb4_bin makes the raw count case-sensitive (838 instead of 827 here).
Other engines
SQLite · PostgreSQL · SQL Server · DuckDB
The data is fictional and released under CC0. AdventureWorks, Northwind and Sakila are well-known sample databases from their vendors; we do not copy them here.