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_idfirst_namelast_namedepartmentsalaryhire_datemanager_id
1KarenMitchellManagement936002018-01-02NULL
2TomBradleySales624002019-04-011
3JuliaReyesSales468002021-06-152
4MarcusAllenSales492002020-09-012
5SarahLongWarehouse396002022-02-011
6FelixTurnerWarehouse354002024-03-185
7NinaCooperAccounting528002019-10-011
8DavidRossCustomer service384002023-05-022
9LauraHughesCustomer serviceNULL2025-09-012
10PaulWardAccounting432002022-11-147

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;
namedepartment
Allen, MarcusSales
Bradley, TomSales
Cooper, NinaAccounting

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 shop and 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_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

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_idnamecategorypricestock
1Copy paper, 500 sheetsPaper4.99420
2Blue ballpoint pens, 10-packWriting3.49310
3Lever arch file, grayFiling2.79185
4Comfort office chairFurniture18912
5Standing deskFurniture4495
6Black ink cartridgePrinter supplies24.964
7Yellow sticky notes, 12 padsWriting6.990
8Mono laser printer L30Electronics2198
927-inch monitorElectronics27915
10Notebook A5, ruledPaper5.49140
11Black toner XLPrinter supplies89.922
12Cross-cut shredderElectronics1290

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.

Next up: the first lesson

The course starts with your very first query and builds up step by step to JOIN, GROUP BY and window functions. Everything you write there also runs on MySQL, apart from the spots covered on this page.

Start with the basics

Write to us

Choose language

Select your preferred language