Learn MySQL: practise standard SQL and the MySQL quirks that matter
Almost everything you write in MySQL is the same SQL this course teaches. This page covers what MySQL is, the handful of places where it does things its own way, and how to get a server running. The exercises run right here in your browser, no install needed.
In short: MySQL is a database system from Oracle that you can use for free as open source software. SELECT, WHERE, JOIN, GROUP BY, CASE and LIMIT look exactly the same there. The main differences: you join text with CONCAT() because || means OR in MySQL, dates use functions such as DATE_FORMAT(), automatic IDs come from AUTO_INCREMENT, and text comparisons usually ignore upper and lower case.
What is MySQL?
MySQL is a relational database management system: data sits in tables and you query it with SQL. Oracle develops, distributes and supports it. The software is open source under the GPL, so anyone can download and use it at no cost. If you want to build MySQL into a commercial product without following the GPL, Oracle sells a commercial licence.
MySQL is a client/server system. A server manages the databases, and programs connect to it: a web application, a reporting tool, or you with a query window. The MySQL manual describes it as well suited to databases accessed over the internet, and most programming languages can talk to it. If you are given access to a MySQL database at work, you will usually connect with a tool like MySQL Workbench and write ordinary SELECT queries.
Why this course works for MySQL
Our exercises run on SQLite inside your browser. The core is shared: SELECT, WHERE, JOIN, GROUP BY, HAVING, CASE, subqueries, CTEs with WITH and window functions such as ROW_NUMBER are written the same way in MySQL. What you practise here carries over almost unchanged. The few spots where MySQL goes its own way are listed below with examples. For all four systems side by side, see MySQL vs PostgreSQL vs SQL Server. When you show the model solution in an exercise, a button above it switches it to the MySQL version.
Try it now
HR wants a staff directory with names written as “Last, First”. Use CONCAT() and the same query will run on MySQL without changes. || also works in this exercise, but in MySQL it means something else entirely (more on that below).
Task HR needs two columns from the employees table for the staff directory: first the name in the form Last, First (for example Mitchell, Karen, with a comma and a space), then the department.
employees 10 rows, 7 columns
| employee_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
Where MySQL differs
Joining text: CONCAT, not ||
SQLite and PostgreSQL join strings with ||. In MySQL, with default settings, || is a logical OR. The manual calls that meaning deprecated and warns it may be removed in a future version. Only with the PIPES_AS_CONCAT SQL mode does || join text in MySQL. The safe choice is CONCAT():
SELECT CONCAT(last_name, ', ', first_name) AS name, department
FROM employees
ORDER BY last_name
LIMIT 3;
| name | department |
|---|---|
| Allen, Marcus | Sales |
| Bradley, Tom | Sales |
| Cooper, Nina | Accounting |
MySQL and our practice database return the same rows here. One catch: if any argument is NULL, MySQL returns NULL for the whole CONCAT(). CONCAT_WS(', ', last_name, first_name) takes a separator as its first argument and skips NULL values, which makes it the better fit for address lines with optional parts.
Limiting rows: LIMIT, just like here
LIMIT 3 at the end of the query, after ORDER BY, works in MySQL exactly as it does in the exercises. Make the sort order unique, though. If several rows share the same value in the ORDER BY column, the manual says MySQL may return them in any order, and the order can even change when you add LIMIT. Adding a unique column such as the ID to ORDER BY keeps the result stable.
Dates: DATE_FORMAT, CURDATE and DATE_ADD
In the exercises, dates are stored as text in YYYY-MM-DD format and you work with date() and strftime(). MySQL has real date types and its own functions:
-- MySQL
SELECT CURDATE(); -- today's date
SELECT DATE_ADD('2026-06-01', INTERVAL 7 DAY); -- 2026-06-08
SELECT LAST_DAY('2026-02-10'); -- 2026-02-28
SELECT YEAR(order_date), MONTH(order_date) FROM orders;
SELECT DATE_FORMAT(order_date, '%Y-%m') AS order_month FROM orders;
-- practice database (SQLite)
SELECT strftime('%Y-%m', order_date) AS order_month FROM orders;
In the format string, %Y is the four-digit year and %m the two-digit month. Type DATE_FORMAT into an exercise and it tells you: “The function DATE_FORMAT does not exist in this practice database (SQLite).” Switch to the SQLite version underneath.
Automatic IDs: AUTO_INCREMENT
CREATE TABLE categories (
category_id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
PRIMARY KEY (category_id)
);
INSERT INTO categories (name) VALUES ('Paper'), ('Electronics');
SELECT LAST_INSERT_ID();
Leave the ID column out of the INSERT and MySQL assigns the next number itself. LAST_INSERT_ID() returns the most recent generated value for your own connection; after a multi-row INSERT it is the value of the first row. SQLite does the same job with an INTEGER PRIMARY KEY column.
Upper and lower case
With the default character set and collation (utf8mb4 and utf8mb4_0900_ai_ci), MySQL compares text without regard to case. LIKE 'a%' finds values starting with A or a, and the same goes for = as long as the column uses the default collation. For an exact comparison, add a case-sensitive collation such as COLLATE utf8mb4_bin. Names of databases and tables work the other way round: on Unix they are case-sensitive, on Windows they are not. Always write them exactly as they were created.
Quoting names: backticks
If a column name is a reserved word or contains a space, wrap it in backticks in MySQL: `order`. Double quotes only count as name quotes when the ANSI_QUOTES SQL mode is on. Text values go in single quotes, as everywhere else.
Create a database in MySQL, plus tools and setup
Once you are connected to a server, these are the first commands you will need:
CREATE DATABASE shop; -- create a new database
USE shop; -- select it (needed in every new session)
SHOW DATABASES; -- list all databases on the server
SHOW TABLES; -- list the tables in the current database
DESCRIBE products; -- columns and data types of a table
SELECT VERSION(); -- server version
- MySQL Workbench: the graphical tool for MySQL, available for Windows, Linux and macOS. You connect to a server, write queries in the SQL editor, manage user accounts and check server status, client connections and the error log. The backup wizard for MySQL Enterprise Backup needs the paid Enterprise Edition. The Community Edition of Workbench is free. The current version 26 replaces Workbench 8.0; visual data modelling with EER diagrams was part of Workbench 8.0.
- The mysql command-line client: a simple SQL shell. Connect with
mysql -h host -u user -p shopand it prompts for your password. - Installing on Windows: the manual recommends the MSI package from the downloads page on dev.mysql.com. It installs the server along with MySQL Configurator, which sets up the server, creates the options file and user accounts, and runs MySQL as a Windows service.
None of this is needed to start learning. The exercises run without any install, and every query you write here comes with you to MySQL later.
Another exercise: month from a date
In MySQL you would write DATE_FORMAT(order_date, '%Y-%m') here. In the practice database, use strftime() with the same pattern.
Task Accounting books every order in the month it was placed. For all orders from January to March 2026, show order_id, order_date and order_month. order_month holds the month as YYYY-MM, for example 2026-01.
orders 18 rows, 5 columns
| order_id | customer_id | order_date | status | employee_id |
|---|---|---|---|---|
| 1001 | 1 | 2026-01-08 | delivered | 3 |
| 1002 | 4 | 2026-01-12 | delivered | 4 |
| 1003 | 3 | 2026-01-20 | delivered | 3 |
| 1004 | 7 | 2026-02-03 | delivered | 4 |
| 1005 | 2 | 2026-02-11 | cancelled | 8 |
| 1006 | 1 | 2026-02-25 | delivered | 3 |
| 1007 | 10 | 2026-03-04 | delivered | 2 |
| 1008 | 5 | 2026-03-17 | delivered | 4 |
| 1009 | 8 | 2026-03-30 | delivered | 3 |
| 1010 | 6 | 2026-04-07 | delivered | 8 |
| 1011 | 12 | 2026-04-22 | delivered | 4 |
| 1012 | 3 | 2026-05-06 | delivered | 3 |
| 1013 | 9 | 2026-05-19 | cancelled | 8 |
| 1014 | 7 | 2026-06-02 | shipped | 4 |
| 1015 | 1 | 2026-06-10 | shipped | 3 |
| 1016 | 11 | 2026-06-12 | open | NULL |
| 1017 | 4 | 2026-06-13 | open | NULL |
| 1018 | 10 | 2026-06-14 | open | NULL |
And one with an automatic ID
The products table numbers its rows itself, just like an AUTO_INCREMENT column in MySQL. Simply leave the ID out of your INSERT.
Task A new product is joining the range: the LED desk lamp in the Electronics category, price 39.90, 25 in stock. Add it to the products table. Leave out product_id; the database assigns it. After Run or Check you will see the row you added.
products 12 rows, 5 columns
| product_id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Copy paper, 500 sheets | Paper | 4.99 | 420 |
| 2 | Blue ballpoint pens, 10-pack | Writing | 3.49 | 310 |
| 3 | Lever arch file, gray | Filing | 2.79 | 185 |
| 4 | Comfort office chair | Furniture | 189 | 12 |
| 5 | Standing desk | Furniture | 449 | 5 |
| 6 | Black ink cartridge | Printer supplies | 24.9 | 64 |
| 7 | Yellow sticky notes, 12 pads | Writing | 6.99 | 0 |
| 8 | Mono laser printer L30 | Electronics | 219 | 8 |
| 9 | 27-inch monitor | Electronics | 279 | 15 |
| 10 | Notebook A5, ruled | Paper | 5.49 | 140 |
| 11 | Black toner XL | Printer supplies | 89.9 | 22 |
| 12 | Cross-cut shredder | Electronics | 129 | 0 |
The lessons that matter most for MySQL
- LIKE: patterns are written the same way. With default settings MySQL’s LIKE ignores case, much as SQLite does for plain letters.
- String functions: CONCAT and CONCAT_WS keep you on safe ground in MySQL.
- Date functions: the approach (pull out the month, add days, filter a date range) is the same; only the function names change.
- ORDER BY and LIMIT: word for word identical.
- JOIN and GROUP BY: the backbone of every report, no differences.
- INSERT, CREATE TABLE and primary and foreign keys: for when you build your own tables in MySQL, where the data types are called INT, VARCHAR, DATE and so on.
FAQ
Is MySQL free?
Yes. As open source software under the GPL, you can download and use MySQL at no cost. You only need a commercial licence if you build MySQL into your own commercial product and do not want to meet the terms of the GPL. MySQL Workbench is available as a free Community Edition.
Do I need to install MySQL to use this course?
No. Every exercise runs in its own small database in your browser. Installing a server only makes sense once you want to work with your own data, or when your job gives you access to one.
Why does my query return more rows in MySQL than in the exercise?
Usually because of case. With default settings MySQL compares text case-insensitively, so WHERE city = 'boston' also matches “Boston” there. In our practice database, = is case-sensitive.
Should I learn MySQL or PostgreSQL?
Your employer usually decides that for you. Either way, solid standard SQL is what counts; the quirks of a particular system are quick to pick up with a cheat sheet like this one. For the PostgreSQL side, see Learn PostgreSQL.
Which MySQL version does this page cover?
Everything here was checked against the MySQL 8.4 Reference Manual. Older versions differ in places; run SELECT VERSION(); to see what you are working with.
Sources: MySQL 8.4 Reference Manual on dev.mysql.com (What is MySQL, Logical Operators, String Functions, Date and Time Functions, Using AUTO_INCREMENT, Case Sensitivity in String Searches, Schema Object Names, LIMIT Query Optimization, Installing MySQL on Microsoft Windows, Creating and Selecting a Database, Getting Information About Databases and Tables, Information Functions), MySQL Workbench Manual.