00:00
Free MySQL Course

MySQL Tutorial

Last updated:

Learn MySQL step by step, from what a database is to joins, indexes, transactions and user management. Every tutorial explains the idea in plain words and shows real queries with the output a MySQL server actually returns.

  • 93 tutorials
  • 15 learning tracks
  • Real query output
  • Beginner to advanced

What Is MySQL?

MySQL is an open-source relational database management system (RDBMS). It stores data in tables made of rows and columns, links tables together with keys, and lets you read and change the data with SQL (Structured Query Language). It was first released in 1995, has been owned by Oracle since 2010, and is available under the GPL licence as well as commercial editions.

MySQL is one of the most widely used databases in the world. It powers content platforms such as WordPress, online shops, banking back offices and countless Java and Spring Boot applications, and every major cloud offers it as a managed service.

TypeRelational database (RDBMS)
First release1995
Current versions8.4 LTS and 9.x
Default engineInnoDB (ACID transactions)

What You Will Learn

  • What databases, SQL, NoSQL and RDBMS are, and how they differ
  • Installing MySQL and choosing the right data types
  • Creating, altering, copying and dropping databases and tables
  • Keeping data valid with primary keys, foreign keys and other constraints
  • Inserting, reading, updating and deleting rows (CRUD)
  • Filtering, sorting and grouping with WHERE, ORDER BY, GROUP BY and HAVING
  • Combining tables with inner, left, right, cross and self joins
  • Speeding up queries with indexes and reading EXPLAIN
  • Transactions, views, users and passwords
  • Answering common MySQL interview questions

Who this is for

Students and beginners learning their first database, Java and Spring Boot developers who work with MySQL every day, and engineers preparing for interviews.

Prerequisites

Basic computer skills. No SQL or programming knowledge is needed to start; the Java examples in later tutorials are optional.

How MySQL Organizes Data

A MySQL server holds several databases; each database holds tables; each table holds rows with the same columns. A primary key identifies every row, and foreign keys link rows in different tables.

MySQL Learning Path

Follow the tracks in order, or jump straight to the topic you need. The same tracks appear in the menu on the left of every MySQL tutorial.

Quick Start: Your First MySQL Queries

Run MySQL 8.4 LTS locally with Docker and open the mysql command-line client. (Already have MySQL installed? Just run mysql -u root -p. Want a full setup guide? See MySQL Installation.)

Terminal
docker run -d --name mysql84 -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 mysql:8.4
docker exec -it mysql84 mysql -u root -p

Create a database and a table, and add a few rows:

first-table.sql
CREATE DATABASE shop;
USE shop;

CREATE TABLE customers (
  id      INT AUTO_INCREMENT PRIMARY KEY,
  name    VARCHAR(50) NOT NULL,
  city    VARCHAR(30) NOT NULL,
  joined  DATE
);

INSERT INTO customers (name, city, joined) VALUES
  ('Asha',   'Pune',      '2025-01-12'),
  ('Ravi',   'Bengaluru', '2025-03-03'),
  ('Meera',  'Pune',      '2025-06-21'),
  ('Kabir',  'Delhi',     '2025-07-09'),
  ('Nisha',  'Bengaluru', '2025-09-30');
Output
Query OK, 1 row affected
Query OK, 0 rows affected
Query OK, 0 rows affected
Query OK, 5 rows affected
Records: 5  Duplicates: 0  Warnings: 0

Ask a question of the data: who joined from Pune, newest first?

filter.sql
SELECT id, name, joined
FROM customers
WHERE city = 'Pune'
ORDER BY joined DESC;

Result: 2 rows

idnamejoined
3Meera2025-06-21
1Asha2025-01-12

Summarise it: how many customers are in each city?

group-by.sql
SELECT city, COUNT(*) AS customers
FROM customers
GROUP BY city
ORDER BY customers DESC, city;

Result: 3 rows

citycustomers
Bengaluru2
Pune2
Delhi1

The output above was produced by running these exact statements on a real MySQL server; MySQL 8.4 returns the same results. Next, learn what each statement does in MySQL Create Table, MySQL WHERE and MySQL GROUP BY.

SQL Command Groups at a Glance

Every MySQL statement belongs to one of five groups. Knowing the group tells you what the statement changes and whether it can be rolled back.

GroupWhat it doesMain statements
DDL (Data Definition)Creates and changes structureCREATE, ALTER, DROP, TRUNCATE, RENAME
DML (Data Manipulation)Adds, changes and removes rowsINSERT, UPDATE, DELETE
DQL (Data Query)Reads rowsSELECT with WHERE, JOIN, GROUP BY
DCL (Data Control)Manages users and permissionsCREATE USER, GRANT, REVOKE
TCL (Transaction Control)Groups changes into all-or-nothing unitsSTART TRANSACTION, COMMIT, ROLLBACK

Read the full guide to SQL

Why Developers Choose MySQL

Proven and Popular

Decades of production use, a huge community, and answers to almost any question already written down.

Reliable Transactions

The InnoDB engine gives ACID transactions, row-level locking and crash recovery by default.

Fast Reads

B-tree indexes, a cost-based optimizer and EXPLAIN make it easy to keep queries quick.

Replication and High Availability

Read replicas, Group Replication and InnoDB Cluster keep data available when a server fails.

Runs Everywhere

Linux, Windows, macOS, Docker, and managed services such as Amazon RDS, Azure and Google Cloud SQL.

Great with Java

Connector/J, Spring Boot, Spring Data JPA and Hibernate all support MySQL out of the box.

MySQL Compared

Choosing a database? These side-by-side guides show where MySQL fits.