Every PHP page that shows a product, a comment or a shopping cart ends in a question put to a database: which rows, in what order, and how fast? In a LAMP stack that database is MySQL 524 , a server that has answered those questions for WordPress 48 , Drupal 2,652 , Magento 12,198 , Laravel 2,157 and a large share of the web since the 1990s. In the 2025 Stack Overflow survey 40.5% of developers used it, second only to PostgreSQL 1,289 , and every shared host and major cloud offers it.
You can use MySQL for years knowing only SELECT, INSERT, UPDATE and DELETE, and then lose a weekend to a query that took 20 ms on your laptop and 40 seconds in production. The gap between the two is the subject of this chapter. It teaches SQL the way the server actually runs it: how a SELECT is evaluated, what an index really is, how the optimizer picks a plan, what isolation level your transaction ran at, and why a GROUP BY that older servers accepted is now an error.
The chapter runs from setup to operations. Getting MySQL Running to Defining Tables install the server and define tables and types; 3.5 to 3.9 cover querying, from joins and subqueries through window functions, JSON, full-text and spatial data; 3.10 to 3.13 deal with design, indexing, the optimizer and server tuning; 3.14 to 3.17 cover transactions, stored routines, accounts and administration; and 3.18 moves the database to the cloud and compares MySQL with its rivals. Most examples query one small bookshop schema of customers, products, orders and reviews, so the chapter reads as one story.
Everything here runs against MySQL 9.7 LTS, the current long-term-support series. PHP's side of the conversation (PDO, bound parameters and connection handling) is in PHP, and Laravel's Eloquent and migrations are in Laravel. MongoDB 1,815 appears only for comparison, since MERN Stack Development covers it in depth.
What you will learn
How MySQL's LTS and Innovation tracks work, and how to install 9.7 LTS on Linux, Windows, macOS and Docker 514
SQL from CREATE TABLE to recursive CTEs, window functions, JSON and full-text search
How to choose data types and constraints, and how to normalize a schema
How InnoDB indexes work, how to read EXPLAIN, and how to tune the server
Transactions, locking, stored routines, users, roles, backups and replication
Sections
- Getting MySQL Running
- SQL Essentials and Basic CRUD
- Data Types
- Defining Tables
- SELECT and Joins
- Subqueries and CTEs
- Functions and Operators
- Aggregates and Windows
- JSON, Full-Text, Spatial
- Design and Normalization
- Indexes
- Optimizer and EXPLAIN
- Server Tuning
- Transactions and Locking
- Routines, Triggers, Views
- Users and Security
- Administration
- MySQL in the Cloud
- Test Yourself!