If you’ve ever built a website with WordPress or PHP, you’ve already used MySQL, even if you never saw it. It’s one of the most popular databases in the world, especially on the web, and it’s free.
This guide explains what MySQL is, how it works, which version to install, and how to create your first database. I use MySQL for web projects alongside SQL Server at work, so I’ll also point out the small differences that trip people up when they move between the two.
Quick answer: what is MySQL?
MySQL is a free, open-source relational database management system (DBMS). It stores data in tables, you talk to it with SQL, and it’s the standard database behind WordPress and a huge number of PHP websites.
Install MySQL 8.4 LTS (the long-term support version), and manage it with MySQL Workbench, phpMyAdmin or the mysql command line.

Table of Contents
What Is MySQL?
MySQL (you can say “My S-Q-L” or “My Sequel”) is a relational database management system: software that stores data in tables, links them with keys, and answers questions written in SQL. If those words are new to you, start with What Is a Database?.
A little history explains a lot about MySQL today:
- It was created in 1995 by a Swedish company, MySQL AB. The “My” comes from the name of co-founder Michael “Monty” Widenius’s daughter.
- Sun Microsystems bought MySQL in 2008, and Oracle bought Sun in 2010. Oracle has developed MySQL ever since.
- Worried about Oracle’s ownership, Monty started a community copy (a fork) called MariaDB, named after his other daughter. MariaDB works almost exactly like MySQL, and many Linux systems and tools ship it instead.
The free Community Edition is open source under the GPL licence. Oracle also sells an Enterprise Edition with extra tools and support, but most people never need it.
What Is MySQL Used For?
- WordPress websites. WordPress, which runs over 40% of all websites, stores every post, page, user and setting in MySQL (or MariaDB).
- PHP applications. Frameworks like Laravel and platforms like Drupal, Joomla and many online shops commonly run on MySQL.
- Web and mobile app back ends. Customer accounts, orders, bookings and messages.
- Large websites. Some of the world’s biggest sites run MySQL at enormous scale, spread over thousands of servers.
Why is it so popular? It’s free, it’s fast for typical website workloads, almost every web host offers it, and twenty-five years of tutorials and answers mean you’re never stuck for long.
How MySQL Works
MySQL is a client-server system:
- The MySQL server runs in the background on a computer, a web host or a cloud server. It owns the data files and listens for connections, by default on port 3306.
- A client connects to the server, sends SQL and gets results back. The client can be a tool like MySQL Workbench or phpMyAdmin, the
mysqlcommand line, or your own application (PHP’s PDO, Python’s connector, Node’s mysql2, and so on).
Inside the server, a part called the storage engine decides how data is actually written to disk. The default, InnoDB, supports transactions, foreign keys and crash recovery. You’ll also see the older MyISAM in old tutorials. It has no transactions or foreign keys, so for new tables, always use InnoDB (which happens automatically).
Which MySQL Version Should You Install?
MySQL now has two kinds of release:
- LTS (long-term support) versions get bug and security fixes for years. MySQL 8.4 LTS is the one to choose for learning and for real projects.
- Innovation releases (the 9.x series) add new features quickly but are supported only for a short time. They’re for people who want to try the newest features.
If you have an older server on MySQL 8.0, plan an upgrade: 8.0 reached end of life in April 2026 and no longer receives security fixes.
How to Install MySQL
- Windows: download MySQL Community Server from the official MySQL website (dev.mysql.com) and run the installer. Install MySQL Workbench from the same site for a visual tool.
- Mac: use the installer from the MySQL website, or
brew install mysqlif you use Homebrew. - Ubuntu Linux:
sudo apt install mysql-server, then runsudo mysql_secure_installationto set a password and remove test settings. - Your web host: most hosting plans include MySQL databases, managed through phpMyAdmin in the control panel.
- Cloud: Amazon RDS, Azure Database for MySQL and Google Cloud SQL run it for you.
A note on XAMPP: the popular XAMPP package (Apache, PHP and a database in one installer) actually ships MariaDB, not MySQL, even though its control panel says “MySQL”. For learning, the difference doesn’t matter. Everything in this guide works on both.
Your First MySQL Database
Here’s the stationery shop from What Is a Database?, created in MySQL. Run it in MySQL Workbench or after connecting with mysql -u root -p:
CREATE DATABASE shop;
USE shop;
CREATE TABLE customers (
customer_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
phone VARCHAR(20),
city VARCHAR(50)
);
CREATE TABLE sales (
sale_id INT AUTO_INCREMENT PRIMARY KEY,
sale_date DATE NOT NULL,
customer_id INT NOT NULL,
product VARCHAR(100) NOT NULL,
amount DECIMAL(10,3) NOT NULL,
CONSTRAINT fk_sales_customers
FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);
INSERT INTO customers (name, phone, city) VALUES
('Sara Ahmed', '3300 1111', 'Manama'),
('Omar Khalid', '3300 2222', 'Riffa');
INSERT INTO sales (sale_date, customer_id, product, amount) VALUES
('2026-11-02', 1, 'Notebook', 2.500),
('2026-11-03', 2, 'Pen set', 4.000),
('2026-11-05', 1, 'Backpack', 18.000);
Now ask it some questions:
-- The two biggest sales, with the customer's name
SELECT c.name, s.product, s.amount
FROM sales s
JOIN customers c ON c.customer_id = s.customer_id
ORDER BY s.amount DESC
LIMIT 2;
-- Sara Ahmed Backpack 18.000
-- Omar Khalid Pen set 4.000
-- Total spent by each customer
SELECT c.name, SUM(s.amount) AS total_spent
FROM customers c
JOIN sales s ON s.customer_id = c.customer_id
GROUP BY c.customer_id, c.name
ORDER BY total_spent DESC;
-- Sara Ahmed 20.500
-- Omar Khalid 4.000
A few MySQL commands you’ll use constantly while exploring:
| Command | What it does |
|---|---|
SHOW DATABASES; | Lists the databases on the server |
USE shop; | Chooses the database to work in |
SHOW TABLES; | Lists the tables in the current database |
DESCRIBE sales; | Shows a table’s columns and types |
SELECT LAST_INSERT_ID(); | Returns the id that AUTO_INCREMENT just created |
MySQL Features You’ll Use Every Day
- AUTO_INCREMENT gives each new row the next number, so you never pick ids by hand.
- Foreign keys (with InnoDB) stop orphan rows, like a sale for a customer who doesn’t exist. Write them as a separate
CONSTRAINT ... FOREIGN KEYline as above. MySQL 8.4 and older silently ignore a shortREFERENCESwritten next to a column (only the 9.x releases enforce it), so the separate line is the safe habit that works in every version. - Transactions make a group of changes all-or-nothing, essential for money and stock. See SQL Transactions and ACID.
- Indexes make searches fast on big tables.
- Modern SQL: since MySQL 8, you also get window functions, CTEs, CHECK constraints and good JSON support.
Where MySQL Is Weaker
MySQL is an excellent database, but it’s fair to know its limits:
- Fewer advanced features than PostgreSQL. For example, there’s no
FULL OUTER JOIN, and PostgreSQL has richer data types and extensions. - Some loose old defaults. Older setups could silently cut long text or accept odd dates. Modern versions run in strict mode by default, which is what you want.
- Oracle ownership. Some teams prefer MariaDB or PostgreSQL for a fully community-run project.
For websites, WordPress, PHP apps and learning SQL, none of these is a problem. If you’re choosing between the two big open-source databases, MySQL vs PostgreSQL compares them in detail.
MySQL Tools
- MySQL Workbench: Oracle’s free desktop tool for writing queries, designing tables and managing users.
- phpMyAdmin: a web-based tool found on most hosting control panels. Great for quick edits, imports and exports.
- DBeaver: a free tool that works with MySQL and many other databases, useful if you work with several.
- The command line:
mysql -u root -p. Fast once you’re comfortable, and it’s always available on a server.
Check Your Understanding
- What does MySQL’s default storage engine, InnoDB, give you that MyISAM doesn’t?
- Which MySQL version should a beginner install in 2026?
- If you install XAMPP, which database do you actually get?
- How do you return only the first 2 rows in MySQL?
- Why should you write foreign keys as a separate
CONSTRAINTline in MySQL?
Answers
- Transactions, foreign keys and crash recovery.
- MySQL 8.4 LTS, the long-term support version. (8.0 reached end of life in April 2026.)
- MariaDB, a close fork of MySQL. It works the same for learning.
- Add
LIMIT 2at the end of the query (SQL Server usesTOP (2)). - Because MySQL 8.4 and older ignore a short
REFERENCESwritten next to a column, so the rule would silently not exist. The separate line works in every version.
Frequently Asked Questions
Is MySQL free?
Yes. MySQL Community Edition is free and open source, including for commercial websites. Oracle sells an Enterprise Edition with extra tools and support, but you don’t need it to learn or to run most websites.
What is the difference between MySQL and SQL?
SQL is the language. MySQL is a database product that understands it. SQL Server, PostgreSQL and Oracle understand SQL too, each with small differences.
Is MariaDB the same as MySQL?
Almost. MariaDB started as a copy of MySQL in 2009 and is still highly compatible for everyday SQL, but the two have slowly drifted apart in advanced features. For learning and for most websites, you can treat them as the same.
Should I learn MySQL or SQL Server?
If you build websites or PHP apps, learn MySQL. If you work (or want to work) in company IT and business software, learn SQL Server. The SQL you learn on one moves easily to the other.
What to Learn Next
- SQL for Complete Beginners: your first queries.
- MySQL vs PostgreSQL: how the two big open-source databases compare.
- SQL Data Types Explained Simply: choosing the right type for each column.
Related articles
- PostgreSQL Tutorial for Beginners: MySQL’s main open-source alternative.
- How to Choose the Right Database Server: a checklist for your next project.
- SQL Server vs MySQL vs PostgreSQL Cheat Sheet: the same tasks in all three.
- SQL INSERT, UPDATE and DELETE: adding and changing data safely.