About Database
The foundations: what a database is, its types, SQL, NoSQL and RDBMS.
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.
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.
WHERE, ORDER BY, GROUP BY and HAVINGEXPLAINStudents and beginners learning their first database, Java and Spring Boot developers who work with MySQL every day, and engineers preparing for interviews.
Basic computer skills. No SQL or programming knowledge is needed to start; the Java examples in later tutorials are optional.
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.
| id | name | city |
|---|---|---|
| 1 | Asha | Pune |
| 2 | Ravi | Bengaluru |
| id | customer_id | amount |
|---|---|---|
| 101 | 1 | 2499.00 |
| 102 | 2 | 899.00 |
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.
The foundations: what a database is, its types, SQL, NoSQL and RDBMS.
What MySQL is, how to install it, its data types and engines, and how it compares.
Create, list, select, rename and drop databases safely.
Create, copy, inspect, empty, lock and drop tables.
Change a table's structure without losing data.
Saved queries that behave like tables.
Rules that keep your data valid: keys, NOT NULL, UNIQUE, CHECK and DEFAULT.
Insert, read, update and delete rows.
Filter, sort, limit and group rows with WHERE, ORDER BY, GROUP BY and HAVING.
Make queries fast and read EXPLAIN plans.
Count, sum and average rows, and find the first and last values.
Auto increment, UNION, comments, transactions, dates and operators.
Combine rows from several tables.
Create users, set passwords and control access.
Common MySQL interview questions with clear answers.
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.)
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:
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');
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?
SELECT id, name, joined
FROM customers
WHERE city = 'Pune'
ORDER BY joined DESC;
Result: 2 rows
| id | name | joined |
|---|---|---|
| 3 | Meera | 2025-06-21 |
| 1 | Asha | 2025-01-12 |
Summarise it: how many customers are in each city?
SELECT city, COUNT(*) AS customers
FROM customers
GROUP BY city
ORDER BY customers DESC, city;
Result: 3 rows
| city | customers |
|---|---|
| Bengaluru | 2 |
| Pune | 2 |
| Delhi | 1 |
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.
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.
| Group | What it does | Main statements |
|---|---|---|
| DDL (Data Definition) | Creates and changes structure | CREATE, ALTER, DROP, TRUNCATE, RENAME |
| DML (Data Manipulation) | Adds, changes and removes rows | INSERT, UPDATE, DELETE |
| DQL (Data Query) | Reads rows | SELECT with WHERE, JOIN, GROUP BY |
| DCL (Data Control) | Manages users and permissions | CREATE USER, GRANT, REVOKE |
| TCL (Transaction Control) | Groups changes into all-or-nothing units | START TRANSACTION, COMMIT, ROLLBACK |
Decades of production use, a huge community, and answers to almost any question already written down.
The InnoDB engine gives ACID transactions, row-level locking and crash recovery by default.
B-tree indexes, a cost-based optimizer and EXPLAIN make it easy to keep queries quick.
Read replicas, Group Replication and InnoDB Cluster keep data available when a server fails.
Linux, Windows, macOS, Docker, and managed services such as Amazon RDS, Azure and Google Cloud SQL.
Connector/J, Spring Boot, Spring Data JPA and Hibernate all support MySQL out of the box.
Choosing a database? These side-by-side guides show where MySQL fits.