DataBrighten

    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.

    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.