Preface |
|
xiii | |
1 Installing MySQL |
|
1 | (58) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
2 | (1) |
|
Installation Choices and Platforms |
|
|
3 | (2) |
|
1 Download the Distribution that You Want to Install |
|
|
4 | (1) |
|
2 Install the Distribution |
|
|
4 | (1) |
|
3 Perform Any Necessary Post-Installation Setup |
|
|
4 | (1) |
|
|
4 | (1) |
|
Installing MySQL on Linux |
|
|
5 | (22) |
|
Installing MySQL on CentOS 7 |
|
|
5 | (7) |
|
Installing MySQL on CentOS 8 |
|
|
12 | (7) |
|
Installing MySQL on Ubuntu 20.04 LTS (Focal Fossa) |
|
|
19 | (8) |
|
Installing MySQL on macOS Big Sur |
|
|
27 | (6) |
|
Installing MySQL on Windows 10 |
|
|
33 | (7) |
|
The Contents of the MySQL Directory |
|
|
40 | (4) |
|
|
41 | (3) |
|
|
44 | (1) |
|
Using the Command-Line Interface |
|
|
44 | (1) |
|
|
45 | (5) |
|
|
45 | (5) |
|
|
50 | (4) |
|
|
51 | (1) |
|
|
51 | (3) |
|
|
54 | (5) |
2 Modeling and Designing Databases |
|
59 | (30) |
|
How Not to Develop a Database |
|
|
59 | (3) |
|
The Database Design Process |
|
|
62 | (1) |
|
The Entity Relationship Model |
|
|
62 | (12) |
|
|
63 | (3) |
|
Representing Relationships |
|
|
66 | (1) |
|
Partial and Total Participation |
|
|
67 | (1) |
|
|
68 | (2) |
|
|
70 | (1) |
|
|
71 | (1) |
|
|
72 | (2) |
|
|
74 | (2) |
|
Normalizing an Example Table |
|
|
76 | (1) |
|
First Normal Form: No Repeating Groups |
|
|
76 | (1) |
|
Second Normal Form: Eliminate Redundant Data |
|
|
76 | (1) |
|
Third Normal Form: Eliminate Data Not Dependent on Key |
|
|
77 | (1) |
|
Entity Relationship Modeling Examples |
|
|
77 | (6) |
|
Using the Entity Relationship Model |
|
|
83 | (6) |
|
Mapping Entities and Relationships to Database Tables |
|
|
83 | (1) |
|
Creating a Bank Database ER Model |
|
|
84 | (1) |
|
Converting the EER to a MySQL Database Using Workbench |
|
|
85 | (4) |
3 Basic SQL |
|
89 | (38) |
|
Using the sakila Database |
|
|
90 | (2) |
|
The SELECT Statement and Basic Querying Techniques |
|
|
92 | (19) |
|
|
93 | (1) |
|
|
94 | (2) |
|
Selecting Rows with the WHERE Clause |
|
|
96 | (9) |
|
|
105 | (2) |
|
|
107 | (2) |
|
|
109 | (2) |
|
|
111 | (6) |
|
|
111 | (3) |
|
|
114 | (3) |
|
|
117 | (3) |
|
|
117 | (1) |
|
Using WHERE, ORDER BY, and LIMIT |
|
|
118 | (1) |
|
Removing All Rows with TRUNCATE |
|
|
119 | (1) |
|
|
120 | (1) |
|
|
120 | (1) |
|
Using WHERE, ORDER BY, and LIMIT |
|
|
121 | (1) |
|
Exploring Databases and Tables with SHOW and mysqlshow |
|
|
121 | (6) |
4 Working with Database Structures |
|
127 | (52) |
|
Creating and Using Databases |
|
|
127 | (3) |
|
|
130 | (40) |
|
|
130 | (3) |
|
Collation and Character Sets |
|
|
133 | (2) |
|
|
135 | (3) |
|
|
138 | (23) |
|
|
161 | (6) |
|
The AUTO_INCREMENT Feature |
|
|
167 | (3) |
|
|
170 | (7) |
|
Adding, Removing, and Changing Columns |
|
|
170 | (4) |
|
Adding, Removing, and Changing Indexes |
|
|
174 | (2) |
|
Renaming Tables and Altering Other Structures |
|
|
176 | (1) |
|
|
177 | (2) |
|
|
177 | (1) |
|
|
178 | (1) |
5 Advanced Querying |
|
179 | (60) |
|
|
179 | (6) |
|
|
180 | (2) |
|
|
182 | (3) |
|
|
185 | (12) |
|
|
185 | (2) |
|
|
187 | (8) |
|
|
195 | (2) |
|
|
197 | (18) |
|
|
197 | (3) |
|
|
200 | (6) |
|
|
206 | (5) |
|
|
211 | (1) |
|
Constant Expressions in Joins |
|
|
212 | (3) |
|
|
215 | (19) |
|
|
215 | (3) |
|
The ANY, SOME, ALL, IN, and NOT IN Clauses |
|
|
218 | (7) |
|
The EXISTS and NOT EXISTS Clauses |
|
|
225 | (6) |
|
Nested Queries in the FROM Clause |
|
|
231 | (2) |
|
|
233 | (1) |
|
|
234 | (5) |
6 Transactions and Locking |
|
239 | (22) |
|
|
241 | (7) |
|
|
242 | (1) |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
245 | (3) |
|
|
248 | (11) |
|
|
249 | (5) |
|
|
254 | (3) |
|
|
257 | (2) |
|
MySQL Parameters Related to Isolation and Locks |
|
|
259 | (2) |
7 Doing More with MySQL |
|
261 | (46) |
|
Inserting Data Using Queries |
|
|
261 | (6) |
|
Loading Data from Comma-Delimited Files |
|
|
267 | (7) |
|
Writing Data into Comma-Delimited Files |
|
|
274 | (3) |
|
Creating Tables with Queries |
|
|
277 | (4) |
|
Performing Updates and Deletes with Multiple Tables |
|
|
281 | (7) |
|
|
281 | (5) |
|
|
286 | (2) |
|
|
288 | (4) |
|
|
292 | (5) |
|
Alternative Storage Engines |
|
|
297 | (10) |
|
|
300 | (1) |
|
|
301 | (1) |
|
|
302 | (2) |
|
|
304 | (3) |
8 Managing Users and Privileges |
|
307 | (44) |
|
Understanding Users and Privileges |
|
|
307 | (2) |
|
|
309 | (1) |
|
Creating and Using New Users |
|
|
310 | (7) |
|
|
317 | (2) |
|
User Management Commands and Logging |
|
|
319 | (2) |
|
Modifying and Dropping Users |
|
|
321 | (7) |
|
|
321 | (4) |
|
|
325 | (3) |
|
|
328 | (13) |
|
Static Versus Dynamic Privileges |
|
|
330 | (1) |
|
|
331 | (1) |
|
Privilege Management Commands |
|
|
332 | (3) |
|
|
335 | (2) |
|
The GRANT OPTION Privilege |
|
|
337 | (4) |
|
|
341 | (6) |
|
Changing root's Password and Insecure Startup |
|
|
347 | (2) |
|
Some Ideas for Secure Setup |
|
|
349 | (2) |
9 Using Option Files |
|
351 | (18) |
|
Structure of the Option File |
|
|
351 | (5) |
|
|
356 | (3) |
|
Search Order for Option Files |
|
|
359 | (1) |
|
|
360 | (4) |
|
Login Path Configuration File |
|
|
360 | (2) |
|
Persistent System Variables Configuration File |
|
|
362 | (2) |
|
Determining the Options in Effect |
|
|
364 | (5) |
10 Backups and Recovery |
|
369 | (42) |
|
Physical and Logical Backups |
|
|
370 | (4) |
|
|
370 | (2) |
|
|
372 | (1) |
|
Overview of Logical and Physical Backups |
|
|
373 | (1) |
|
Replication as a Backup Tool |
|
|
374 | (2) |
|
|
375 | (1) |
|
|
375 | (1) |
|
|
376 | (6) |
|
Bootstrapping Replication with mysqldump |
|
|
382 | (1) |
|
Loading Data from a SQL Dump File |
|
|
382 | (1) |
|
|
383 | (2) |
|
|
385 | (2) |
|
Cold Backup and Filesystem Snapshots |
|
|
387 | (1) |
|
|
388 | (8) |
|
Backing Up and Recovering |
|
|
390 | (3) |
|
|
393 | (1) |
|
Incremental Backups with XtraBackup |
|
|
394 | (2) |
|
Other Physical Backup Tools |
|
|
396 | (1) |
|
|
396 | (1) |
|
|
396 | (1) |
|
|
397 | (5) |
|
Technical Background on Binary Logs |
|
|
398 | (1) |
|
|
399 | (1) |
|
Identifying a PITR Target |
|
|
399 | (2) |
|
Point-in-Time-Recovery Example: XtraBackup |
|
|
401 | (1) |
|
Point-in-Time-Recovery Example: mysqldump |
|
|
402 | (1) |
|
Exporting and Importing InnoDB Tablespaces |
|
|
402 | (5) |
|
|
403 | (1) |
|
|
403 | (2) |
|
|
405 | (1) |
|
XtraBackup Single-Table Restore |
|
|
406 | (1) |
|
Testing and Verifying Your Backups |
|
|
407 | (2) |
|
Database Backup Strategy Primer |
|
|
409 | (2) |
11 Configuring and Tuning the Server |
|
411 | (16) |
|
|
411 | (1) |
|
|
412 | (15) |
|
|
412 | (1) |
|
|
413 | (14) |
12 Monitoring MySQL Servers |
|
427 | (62) |
|
|
428 | (22) |
|
|
428 | (8) |
|
|
436 | (5) |
|
|
441 | (5) |
|
|
446 | (4) |
|
MySQL Server Observability |
|
|
450 | (24) |
|
|
451 | (2) |
|
|
453 | (14) |
|
|
467 | (4) |
|
InnoDB Engine Status Report |
|
|
471 | (3) |
|
|
474 | (3) |
|
|
474 | (2) |
|
|
476 | (1) |
|
|
477 | (6) |
|
Incident/Diagnostic and Manual Data Collection |
|
|
483 | (6) |
|
Gathering System Status Variable Values Periodically |
|
|
483 | (1) |
|
Using pt-stalk to Collect MySQL and OS Metrics |
|
|
484 | (1) |
|
Extended Manual Data Collection |
|
|
485 | (4) |
13 High Availability |
|
489 | (24) |
|
|
490 | (17) |
|
Basic Parameters to Set on the Source and the Replica |
|
|
492 | (1) |
|
Creating a Replica Using PerconaXtraBackup |
|
|
493 | (2) |
|
Creating a Replica Using the Clone Plugin |
|
|
495 | (3) |
|
Creating a Replica Using mysqldump |
|
|
498 | (1) |
|
Creating a Replica Using mydumper and myloader |
|
|
499 | (2) |
|
|
501 | (6) |
|
|
507 | (6) |
|
|
509 | (4) |
14 MySQL in the Cloud |
|
513 | (22) |
|
Database-as-a-Service (DBaaS) |
|
|
513 | (13) |
|
Amazon RDS for MySQL/MariaDB |
|
|
514 | (5) |
|
Google Cloud SQL for MySQL |
|
|
519 | (4) |
|
|
523 | (3) |
|
|
526 | (1) |
|
|
527 | (1) |
|
|
527 | (8) |
|
Deploying Percona XtraDB Cluster in Kubernetes |
|
|
529 | (6) |
15 Load Balancing MySQL |
|
535 | (18) |
|
Load Balancing with Application Drivers |
|
|
535 | (1) |
|
|
536 | (6) |
|
Installing and Configuring ProxySQL |
|
|
538 | (4) |
|
|
542 | (5) |
|
Installing and Configuring HAProxy |
|
|
543 | (4) |
|
|
547 | (6) |
16 Miscellaneous Topics |
|
553 | (24) |
|
|
553 | (10) |
|
|
553 | (1) |
|
Installing MySQL Shell on Ubuntu 20.04 Focal Fossa |
|
|
553 | (1) |
|
Installing MySQL Shell on CentOS 8 |
|
|
554 | (1) |
|
Deploying a Sandbox InnoDB Cluster with MySQL Shell |
|
|
555 | (4) |
|
|
559 | (4) |
|
|
563 | (2) |
|
Building MySQL from Source |
|
|
565 | (5) |
|
Building MySQL for Ubuntu Focal Fossa and ARM Processors |
|
|
566 | (4) |
|
|
570 | (7) |
Index |
|
577 | |