00:00

MySQL Introduction

Last updated:

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

YearEvent
1995First release by the Swedish company MySQL AB, founded by Michael Widenius, David Axmark and Allan Larsson.
2000MySQL becomes open source under the GPL.
2008Sun Microsystems buys MySQL AB.
2009Widenius starts MariaDB, a community fork of MySQL.
2010Oracle buys Sun, and MySQL becomes an Oracle product.
2010MySQL 5.5 makes InnoDB the default storage engine.
2018MySQL 8.0: window functions, CTEs, roles, a transactional data dictionary and much more.
2023New release model: frequent Innovation releases (8.1, 8.2 … 9.x) plus LTS (long-term support) releases.
2024MySQL 8.4 LTS and the first 9.x Innovation release.

3. Editions and Versions

EditionLicence / costWhat you get
Community EditionFree, GPLThe full database server and tools; what this tutorial uses
Enterprise EditionCommercial subscriptionExtra tools (Enterprise Backup, Monitor, Audit, Firewall) and Oracle support
HeatWave (cloud)Pay as you goOracle's managed MySQL service with an in-memory analytics engine
Other managed servicesPay as you goAmazon RDS / Aurora, Azure Database for MySQL, Google Cloud SQL
For production systems choose an LTS release (such as 8.4), which receives fixes for years. Innovation releases get new features first but are supported only until the next release.

4. How MySQL Works: Client-Server Architecture

MySQL client-server architectureClients such as the mysql command line, MySQL Workbench and a Java application connect to the MySQL server on port 3306. Inside the server, the connection layer handles logins, the SQL layer parses and optimizes queries, and the storage engine layer (InnoDB) reads and writes data and log files on disk.mysql CLIcommand lineWorkbenchGUI toolJava appJDBC driverall connect over TCP port 3306MySQL Server (mysqld)Connection layerlogins, threads, SSLSQL layerparser → optimizer → executorStorage enginesInnoDB (default), MyISAM, MEMORYData on disk.ibd files, redo log
Figure 1: MySQL is a server; tools and applications are clients that send it SQL over the network.
  • 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:

query.sql
SELECT CURRENT_USER() AS user_name, DATABASE() AS current_db, 7 * 6 AS answer;

Result: 1 row

user_namecurrent_dbanswer
root@localhostNULL42

List the databases on the server. A fresh server has only its system databases:

query.sql
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:

first-queries.sql
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_iditempriceveg
4Filter Coffee40.001
1Masala Dosa120.001
2Paneer Roll150.001
MySQL stores BOOLEAN as TINYINT(1), so TRUE shows as 1 and FALSE as 0.

6. The Built-in System Databases

DatabasePurpose
mysqlUser accounts, privileges, time zones and other server settings
information_schemaRead-only views describing every database, table, column and index
performance_schemaLow-level statistics about what the server is doing
sysFriendly views built on performance_schema for tuning and troubleshooting

For example, information_schema can tell you about the table you just created:

query.sql
SELECT table_name, engine, table_rows
FROM information_schema.tables
WHERE table_schema = 'cafe';

Result: 1 row

TABLE_NAMEENGINETABLE_ROWS
menuInnoDB4
Never create your own tables in these databases or change them directly; use normal SQL statements such as 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

TermMeaning
Server / mysqldThe MySQL program that stores data and answers queries
Client / mysqlA 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
TableRows and columns holding one kind of data
QueryA SQL statement, usually a SELECT
Storage engineThe component that physically stores table data; InnoDB by default
Port 3306The default network port MySQL listens on

9. Practice Exercises

Exercise 1: Show the menu items that cost less than 150, cheapest first.
solution.sql
SELECT item, price FROM menu WHERE price < 150 ORDER BY price;

Result: 2 rows

itemprice
Filter Coffee40.00
Masala Dosa120.00
Exercise 2: Find the average price of the vegetarian items.
solution.sql
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: mysqld serves 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.