MySQL Introduction
MySQL is a free, open-source relational database management system (RDBMS). It stores data in tables and lets you manage that data with SQL. It powers millions of applications, from small blogs to some of the busiest websites in the world.
This tutorial introduces MySQL: what it is, where it came from, which editions and versions exist, how its client-server architecture works, and how to run your first queries.
1. What is MySQL?
- Relational: data lives in tables that are linked by keys.
- SQL-based: you create, read, update and delete data with standard SQL plus some MySQL extras.
- Client-server: a server program (
mysqld) holds the data; clients connect to it. - Open source: the Community Edition is free under the GNU GPL licence; Oracle also sells a commercial Enterprise Edition.
- Cross-platform: runs on Linux, Windows, macOS and in every major cloud.
The name combines My, the name of co-founder Michael Widenius's daughter, with SQL. The dolphin in the logo is called Sakila.
2. A Short History
| Year | Event |
|---|---|
| 1995 | First release by the Swedish company MySQL AB, founded by Michael Widenius, David Axmark and Allan Larsson. |
| 2000 | MySQL becomes open source under the GPL. |
| 2008 | Sun Microsystems buys MySQL AB. |
| 2009 | Widenius starts MariaDB, a community fork of MySQL. |
| 2010 | Oracle buys Sun, and MySQL becomes an Oracle product. |
| 2010 | MySQL 5.5 makes InnoDB the default storage engine. |
| 2018 | MySQL 8.0: window functions, CTEs, roles, a transactional data dictionary and much more. |
| 2023 | New release model: frequent Innovation releases (8.1, 8.2 … 9.x) plus LTS (long-term support) releases. |
| 2024 | MySQL 8.4 LTS and the first 9.x Innovation release. |
3. Editions and Versions
| Edition | Licence / cost | What you get |
|---|---|---|
| Community Edition | Free, GPL | The full database server and tools; what this tutorial uses |
| Enterprise Edition | Commercial subscription | Extra tools (Enterprise Backup, Monitor, Audit, Firewall) and Oracle support |
| HeatWave (cloud) | Pay as you go | Oracle's managed MySQL service with an in-memory analytics engine |
| Other managed services | Pay as you go | Amazon RDS / Aurora, Azure Database for MySQL, Google Cloud SQL |
4. How MySQL Works: Client-Server Architecture
- Connection layer: accepts network connections (port 3306 by default), checks user name, password and host, and gives each connection a thread.
- SQL layer: parses the SQL, checks privileges, lets the optimizer choose the cheapest plan (for example, which index to use), and executes it.
- Storage engine layer: actually stores and fetches rows. MySQL's special design is that engines are pluggable; InnoDB is the default and supports transactions, row locking and crash recovery.
5. Your First MySQL Queries
Once connected (see MySQL Installation), you can ask the server about itself. These functions work without any table:
SELECT CURRENT_USER() AS user_name, DATABASE() AS current_db, 7 * 6 AS answer;
Result: 1 row
| user_name | current_db | answer |
|---|---|---|
| root@localhost | NULL | 42 |
List the databases on the server. A fresh server has only its system databases:
SHOW DATABASES;
Result: 4 rows
| Database |
|---|
| information_schema |
| mysql |
| performance_schema |
| sys |
Now create a database and a table, add rows and read them back:
CREATE DATABASE cafe;
USE cafe;
CREATE TABLE menu (
item_id INT AUTO_INCREMENT PRIMARY KEY,
item VARCHAR(40) NOT NULL,
price DECIMAL(6,2) NOT NULL,
veg BOOLEAN DEFAULT TRUE
);
INSERT INTO menu (item, price, veg) VALUES
('Masala Dosa', 120.00, TRUE),
('Paneer Roll', 150.00, TRUE),
('Chicken Biryani', 260.00, FALSE),
('Filter Coffee', 40.00, TRUE);
SELECT * FROM menu WHERE veg = TRUE ORDER BY price;
Result: 3 rows
| item_id | item | price | veg |
|---|---|---|---|
| 4 | Filter Coffee | 40.00 | 1 |
| 1 | Masala Dosa | 120.00 | 1 |
| 2 | Paneer Roll | 150.00 | 1 |
BOOLEAN as TINYINT(1), so TRUE shows as 1 and FALSE as 0.6. The Built-in System Databases
| Database | Purpose |
|---|---|
mysql | User accounts, privileges, time zones and other server settings |
information_schema | Read-only views describing every database, table, column and index |
performance_schema | Low-level statistics about what the server is doing |
sys | Friendly views built on performance_schema for tuning and troubleshooting |
For example, information_schema can tell you about the table you just created:
SELECT table_name, engine, table_rows
FROM information_schema.tables
WHERE table_schema = 'cafe';
Result: 1 row
| TABLE_NAME | ENGINE | TABLE_ROWS |
|---|---|---|
| menu | InnoDB | 4 |
CREATE USER instead.7. Who Uses MySQL and Why
MySQL is the "M" in the classic LAMP stack (Linux, Apache, MySQL, PHP/Python/Perl). WordPress, Drupal and many e-commerce platforms run on it, and large companies such as Facebook (Meta), Uber, Booking.com, GitHub and YouTube have used it at huge scale.
- Easy to start: installs in minutes and works on a laptop.
- Fast and reliable: InnoDB handles heavy read-write workloads with crash safety.
- Scales: replication, Group Replication and InnoDB Cluster spread load and protect against failures.
- Huge ecosystem: drivers for every language (JDBC for Java), ORMs such as Hibernate, and countless tutorials.
- Free: the Community Edition costs nothing.
See MySQL Features for a full feature tour.
8. Key Terms You Will Meet
| Term | Meaning |
|---|---|
Server / mysqld | The MySQL program that stores data and answers queries |
Client / mysql | A program that connects to the server, such as the command-line client |
| Database (schema) | A named container of tables; in MySQL the two words mean the same thing |
| Table | Rows and columns holding one kind of data |
| Query | A SQL statement, usually a SELECT |
| Storage engine | The component that physically stores table data; InnoDB by default |
| Port 3306 | The default network port MySQL listens on |
9. Practice Exercises
Exercise 1: Show the menu items that cost less than 150, cheapest first.
SELECT item, price FROM menu WHERE price < 150 ORDER BY price;
Result: 2 rows
| item | price |
|---|---|
| Filter Coffee | 40.00 |
| Masala Dosa | 120.00 |
Exercise 2: Find the average price of the vegetarian items.
SELECT ROUND(AVG(price), 2) AS avg_veg_price FROM menu WHERE veg = TRUE;
Result: 1 row
| avg_veg_price |
|---|
| 103.33 |
10. Summary
- MySQL is a free, open-source relational database owned by Oracle since 2010.
- It uses a client-server design:
mysqldserves many clients over port 3306. - The server has a connection layer, an SQL layer and pluggable storage engines (InnoDB by default).
- Choose LTS releases for production; Innovation releases bring new features first.
- You manage everything with SQL:
CREATE DATABASE,CREATE TABLE,INSERT,SELECT.