Himanshu SharmaSoftware engineer
Let’s talk

MySQL · Lesson 1 of 50

What MySQL is and how it works

Learn what a relational database is, how MySQL stores data in tables, and how SQL, the server and the client fit together before you install anything.

12 minGetting startedUpdated 22 October 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonExplain what MySQL is, how tables, rows and columns store data, and how a client talks to the server with SQL.

Why databases exist

Every useful application remembers things: customers, orders, posts, scores. You could keep that information in text files, but the moment two people use the app at once, or you need to find every order from last March, files stop working. A database is software built for exactly this job. It stores data safely on disk, lets many users read and write at the same time, finds records quickly and refuses to save data that breaks your rules.

MySQL is one of the most widely used databases in the world. It runs behind WordPress sites, Laravel and PHP applications, and countless business systems. It is open source, free to use, and fast enough for small projects and very large ones alike.

The relational model

MySQL is a relational database. That means data lives in tables, and tables can be linked to each other.

A table looks like a spreadsheet:

  • A column has a name and a data type, such as email (text) or price (a decimal number). Columns describe the shape of the data.
  • A row is one record, for example one customer. Every row has a value for every column, although that value can be NULL ("unknown").
  • A primary key is a column (or a few columns) whose value is different in every row, so each record can be identified exactly.

The "relation" part is what makes this powerful. Instead of copying a customer's address onto every order, you store the customer once and each order stores the customer's id. To see an order together with its customer, you join the two tables at query time. You will do this in the joins section.

text
customers                         orders
id | first_name | city           id | customer_id | order_date
1  | Asha       | Delhi          1  | 1           | 2024-01-05
2  | Ben        | London         3  | 2           | 2024-01-20

Here orders.customer_id points to customers.id. That link is called a foreign key relationship.

Server, client and SQL

Three pieces work together:

  1. The server (mysqld) is a program that runs in the background. It owns the data files, enforces rules and executes your requests.
  2. A client connects to the server over the network (or a local socket). The mysql command-line program, MySQL Workbench and your PHP, Python or Node application are all clients.
  3. SQL (Structured Query Language) is the language a client sends. It is a standard shared by most databases. MySQL adds some extras of its own, which this course marks when they come up.

When you type a statement, the client sends the text to the server, the server works out the fastest way to answer it, and sends back a result set: a small table of rows.

sql
SELECT 2 + 3 AS total;
result
+-------+
| total |
+-------+
|     5 |
+-------+

That query does not touch any table. It only asks the server to calculate. Once you have installed MySQL and loaded the sample database, queries like this one will read real data:

sql
SELECT first_name, city FROM customers LIMIT 3;
result
+------------+--------+
| first_name | city   |
+------------+--------+
| Asha       | Delhi  |
| Ben        | London |
| Chloe      | Paris  |
+------------+--------+

The kinds of SQL statement

SQL statements are usually grouped by what they do. The names are worth knowing because documentation and job interviews use them.

Group Meaning Examples
Query Read data, change nothing SELECT
DML (data manipulation) Change the rows INSERT, UPDATE, DELETE
DDL (data definition) Change the structure CREATE TABLE, ALTER TABLE, DROP TABLE
DCL (data control) Control who may do what GRANT, REVOKE
TCL (transaction control) Group changes so they succeed or fail together START TRANSACTION, COMMIT, ROLLBACK

This course follows roughly that order: you read data first, then change it, then learn to design tables, and finally cover speed, safety and advanced features.

MySQL, MariaDB and PostgreSQL

MySQL is owned by Oracle and developed in the open. MariaDB began as a community fork of MySQL and still behaves very similarly for everyday work. PostgreSQL is a separate project with a different history and some different syntax. Everything in the first sections of this course (SELECT, joins, grouping) works almost unchanged on all of them, so the skills carry over.

The examples in this course were run on MySQL 8.4 LTS, a long-term support release. Where a feature needs MySQL 8.0 or newer, such as window functions, the lesson says so.

What you need

A computer you can install software on and a little patience. You do not need to know programming. In the next lesson you install the server, then you connect to it and load a small shop database that every later lesson reuses.

Common mistakes

  • Thinking MySQL is the same thing as SQL. SQL is the language; MySQL is one server that understands it.
  • Treating a table like a spreadsheet you can sort by hand. Rows in a table have no guaranteed order unless your query asks for one.
  • Storing the same fact in many places. Copying a customer's address onto every order makes updates painful. Store it once and link to it.
  • Forgetting that the server must be running. If a client cannot connect, the first thing to check is whether the server process is up.

Exercise

Without running anything, answer these about a library system that has a books table and a members table:

  1. Name three columns the books table might have, and say which could be the primary key.
  2. A member borrows a book. Which table would you add so the link is stored once, and which two foreign keys would it hold?
  3. Is INSERT a query, DML or DDL?
Show one possible answer
  1. isbn, title, author. The isbn (or a separate numeric id) is a good primary key because it is different for every book.
  2. A loans table with a book_id that points to books and a member_id that points to members, plus perhaps a borrowed_on date.
  3. DML, because it changes rows.

Key points

  • MySQL is a relational database server. It stores data in tables made of rows and columns and answers requests written in SQL.
  • A client program (the mysql command, Workbench, or your application) connects to the server and sends SQL; the server never draws a screen by itself.
  • SQL statements fall into groups. Reading data is a query, changing data is DML, changing structure is DDL, permissions are DCL and transactions are TCL.
  • MySQL is one product that speaks SQL. MariaDB and PostgreSQL are others, and most of what you learn here transfers.

Check yourself

1. What does a row in a MySQL table represent?
2. Which program actually stores your data and answers queries?
3. SELECT is part of which kind of SQL statement?
4. Which is a different relational database product that also understands SQL?