Tải bản đầy đủ (.pdf) (762 trang)

MySQL high availability, 2nd edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (18.85 MB, 762 trang )

www.it-ebooks.info


www.it-ebooks.info


SECOND EDITION

MySQL High Availability

Charles Bell, Mats Kindahl, and Lars Thalmann

www.it-ebooks.info


MySQL High Availability, Second Edition
by Charles Bell, Mats Kindahl, and Lars Thalmann
Copyright © 2014 Charles Bell, Mats Kindahl, Lars Thalmann. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (). For more information, contact our corporate/
institutional sales department: 800-998-9938 or

Editor: Andy Oram
Production Editor: Nicole Shelby
Copyeditor: Jasmine Kwityn
Proofreader: Linley Dolby
June 2010:

First Edition



April 2014:

Second Edition

Indexer: Lucie Haskins
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Rebecca Demarest

Revision History for the Second Edition:
2014-04-09:

First release

See for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc. MySQL High Availability, the image of an American robin, and related trade dress are trademarks
of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.

ISBN: 978-1-449-33958-6
[LSI]

www.it-ebooks.info



Table of Contents

Foreword for the Second Edition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Foreword for the First Edition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Part I.

High Availability and Scalability

1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What’s This Replication Stuff, Anyway?
So, Backups Are Not Needed Then?
What’s With All the Monitoring?
Is There Anything Else I Can Read?
Conclusion

5
7
7
8
9

2. MySQL Replicant Library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Basic Classes and Functions
Supporting Different Operating Systems
Servers
Server Roles

Conclusion

15
16
17
19
21

3. MySQL Replication Fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Basic Steps in Replication
Configuring the Master
Configuring the Slave
Connecting the Master and Slave
A Brief Introduction to the Binary Log
What’s Recorded in the Binary Log
Watching Replication in Action
The Binary Log’s Structure and Content

24
25
27
28
29
30
30
33
iii

www.it-ebooks.info



Adding Slaves
Cloning the Master
Cloning a Slave
Scripting the Clone Operation
Performing Common Tasks with Replication
Reporting
Conclusion

35
37
39
41
42
43
49

4. The Binary Log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Structure of the Binary Log
Binlog Event Structure
Event Checksums
Logging Statements
Logging Data Manipulation Language Statements
Logging Data Definition Language Statements
Logging Queries
LOAD DATA INFILE Statements
Binary Log Filters
Triggers, Events, and Stored Routines
Stored Procedures
Stored Functions

Events
Special Constructions
Nontransactional Changes and Error Handling
Logging Transactions
Transaction Cache
Distributed Transaction Processing Using XA
Binary Log Group Commit
Row-Based Replication
Enabling Row-based Replication
Using Mixed Mode
Binary Log Management
The Binary Log and Crash Safety
Binlog File Rotation
Incidents
Purging the Binlog File
The mysqlbinlog Utility
Basic Usage
Interpreting Events
Binary Log Options and Variables
Options for Row-Based Replication

iv

|

Table of Contents

www.it-ebooks.info

52

54
56
58
58
59
59
65
67
70
75
78
81
82
83
86
87
91
94
97
98
99
100
100
101
103
104
105
106
113
118

120


Conclusion

121

5. Replication for High Availability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Redundancy
Planning
Slave Failures
Master Failures
Relay Failures
Disaster Recovery
Procedures
Hot Standby
Dual Masters
Slave Promotion
Circular Replication
Conclusion

124
126
127
127
127
127
128
130
135

144
149
151

6. MySQL Replication for Scale-Out. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Scaling Out Reads, Not Writes
The Value of Asynchronous Replication
Managing the Replication Topology
Application-Level Load Balancing
Hierarchical Replication
Setting Up a Relay Server
Adding a Relay in Python
Specialized Slaves
Filtering Replication Events
Using Filtering to Partition Events to Slaves
Managing Consistency of Data
Consistency in a Nonhierarchical Deployment
Consistency in a Hierarchical Deployment
Conclusion

155
156
158
162
170
171
172
173
174
176

177
178
180
187

7. Data Sharding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
What Is Sharding?
Why Should You Shard?
Limitations of Sharding
Elements of a Sharding Solution
High-Level Sharding Architecture
Partitioning the Data
Shard Allocation
Mapping the Sharding Key
Sharding Scheme

190
191
192
194
196
197
202
206
206

Table of Contents

www.it-ebooks.info


|

v


Shard Mapping Functions
Processing Queries and Dispatching Transactions
Handling Transactions
Dispatching Queries
Shard Management
Moving a Shard to a Different Node
Splitting Shards
Conclusion

210
215
216
218
220
220
225
225

8. Replication Deep Dive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Replication Architecture Basics
The Structure of the Relay Log
The Replication Threads
Starting and Stopping the Slave Threads
Running Replication over the Internet
Setting Up Secure Replication Using Built-in Support

Setting Up Secure Replication Using Stunnel
Finer-Grained Control Over Replication
Information About Replication Status
Options for Handling Broken Connections
How the Slave Processes Events
Housekeeping in the I/O Thread
SQL Thread Processing
Semisynchronous Replication
Configuring Semisynchronous Replication
Monitoring Semisynchronous Replication
Global Transaction Identifiers
Setting Up Replication Using GTIDs
Failover Using GTIDs
Slave Promotion Using GTIDs
Replication of GTIDs
Slave Safety and Recovery
Syncing, Transactions, and Problems with Database Crashes
Transactional Replication
Rules for Protecting Nontransactional Statements
Multisource Replication
Details of Row-Based Replication
Table_map Events
The Structure of Row Events
Execution of Row Event
Events and Triggers
Filtering in Row-Based Replication

vi

|


Table of Contents

www.it-ebooks.info

228
229
233
234
235
237
238
239
239
248
249
249
250
257
258
259
260
261
263
264
266
268
268
270
274

275
278
280
282
283
284
286


Partial Row Replication
Conclusion

288
289

9. MySQL Cluster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
What Is MySQL Cluster?
Terminology and Components
How Does MySQL Cluster Differ from MySQL?
Typical Configuration
Features of MySQL Cluster
Local and Global Redundancy
Log Handling
Redundancy and Distributed Data
Architecture of MySQL Cluster
How Data Is Stored
Partitioning
Transaction Management
Online Operations
Example Configuration

Getting Started
Starting a MySQL Cluster
Testing the Cluster
Shutting Down the Cluster
Achieving High Availability
System Recovery
Node Recovery
Replication
Achieving High Performance
Considerations for High Performance
High Performance Best Practices
Conclusion

Part II.

292
292
293
293
294
296
297
297
298
300
303
304
304
306
306

308
313
314
314
317
318
319
324
325
326
328

Monitoring and Managing

10. Getting Started with Monitoring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Ways of Monitoring
Benefits of Monitoring
System Components to Monitor
Processor
Memory
Disk
Network Subsystem

334
335
335
336
337
338
339


Table of Contents

www.it-ebooks.info

|

vii


Monitoring Solutions
Linux and Unix Monitoring
Process Activity
Memory Usage
Disk Usage
Network Activity
General System Statistics
Automated Monitoring with cron
Mac OS X Monitoring
System Profiler
Console
Activity Monitor
Microsoft Windows Monitoring
The Windows Experience
The System Health Report
The Event Viewer
The Reliability Monitor
The Task Manager
The Performance Monitor
Monitoring as Preventive Maintenance

Conclusion

340
341
342
347
350
353
355
356
356
357
359
361
365
366
367
369
372
374
375
377
377

11. Monitoring MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
What Is Performance?
MySQL Server Monitoring
How MySQL Communicates Performance
Performance Monitoring
SQL Commands

The mysqladmin Utility
MySQL Workbench
Third-Party Tools
The MySQL Benchmark Suite
Server Logs
Performance Schema
Concepts
Getting Started
Using Performance Schema to Diagnose Performance Problems
MySQL Monitoring Taxonomy
Database Performance
Measuring Database Performance
Best Practices for Database Optimization
Best Practices for Improving Performance

viii

| Table of Contents

www.it-ebooks.info

380
381
381
382
383
389
391
402
405

407
409
410
412
420
421
423
423
435
444


Everything Is Slow
Slow Queries
Slow Applications
Slow Replication
Conclusion

444
444
445
445
446

12. Storage Engine Monitoring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
InnoDB
Using the SHOW ENGINE Command
Using InnoDB Monitors
Monitoring Logfiles
Monitoring the Buffer Pool

Monitoring Tablespaces
Using INFORMATION_SCHEMA Tables
Using PERFORMANCE_SCHEMA Tables
Other Parameters to Consider
Troubleshooting Tips for InnoDB
MyISAM
Optimizing Disk Storage
Repairing Your Tables
Using the MyISAM Utilities
Storing a Table in Index Order
Compressing Tables
Defragmenting Tables
Monitoring the Key Cache
Preloading Key Caches
Using Multiple Key Caches
Other Parameters to Consider
Conclusion

448
450
453
457
458
460
461
462
463
464
467
467

468
468
470
471
471
471
472
473
474
475

13. Replication Monitoring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Getting Started
Server Setup
Inclusive and Exclusive Replication
Replication Threads
Monitoring the Master
Monitoring Commands for the Master
Master Status Variables
Monitoring Slaves
Monitoring Commands for the Slave
Slave Status Variables
Replication Monitoring with MySQL Workbench

477
478
478
481
483
483

487
487
487
492
493

Table of Contents

www.it-ebooks.info

|

ix


Other Items to Consider
Networking
Monitor and Manage Slave Lag
Causes and Cures for Slave Lag
Working with GTIDs
Conclusion

495
495
496
497
498
499

14. Replication Troubleshooting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

What Can Go Wrong
Problems on the Master
Master Crashed and Memory Tables Are in Use
Master Crashed and Binary Log Events Are Missing
Query Runs Fine on the Master but Not on the Slave
Table Corruption After a Crash
Binary Log Is Corrupt on the Master
Killing Long-Running Queries for Nontransactional Tables
Unsafe Statements
Problems on the Slave
Slave Server Crashed and Replication Won’t Start
Slave Connection Times Out and Reconnects Frequently
Query Results Are Different on the Slave than on the Master
Slave Issues Errors when Attempting to Restart with SSL
Memory Table Data Goes Missing
Temporary Tables Are Missing After a Slave Crash
Slave Is Slow and Is Not Synced with the Master
Data Loss After a Slave Crash
Table Corruption After a Crash
Relay Log Is Corrupt on the Slave
Multiple Errors During Slave Restart
Consequences of a Failed Transaction on the Slave
I/O Thread Problems
SQL Thread Problems: Inconsistencies
Different Errors on the Slave
Advanced Replication Problems
A Change Is Not Replicated Among the Topology
Circular Replication Issues
Multimaster Issues
The HA_ERR_KEY_NOT_FOUND Error

GTID Problems
Tools for Troubleshooting Replication
Best Practices
Know Your Topology

x

|

Table of Contents

www.it-ebooks.info

502
503
503
503
505
505
506
507
507
509
510
510
511
512
513
513
513

514
514
515
515
515
515
516
517
517
517
518
518
519
519
520
521
521


Check the Status of All of Your Servers
Check Your Logs
Check Your Configuration
Conduct Orderly Shutdowns
Conduct Orderly Restarts After a Failure
Manually Execute Failed Queries
Don’t Mix Transactional and Nontransactional Tables
Common Procedures
Reporting Replication Bugs
Conclusion


523
523
524
525
525
526
526
526
528
529

15. Protecting Your Investment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
What Is Information Assurance?
The Three Practices of Information Assurance
Why Is Information Assurance Important?
Information Integrity, Disaster Recovery, and the Role of Backups
High Availability Versus Disaster Recovery
Disaster Recovery
The Importance of Data Recovery
Backup and Restore
Backup Tools and OS-Level Solutions
MySQL Enterprise Backup
MySQL Utilities Database Export and Import
The mysqldump Utility
Physical File Copy
Logical Volume Manager Snapshots
XtraBackup
Comparison of Backup Methods
Backup and MySQL Replication
Backup and Recovery with Replication

PITR
Automating Backups
Conclusion

532
532
533
533
534
535
541
542
547
548
559
560
562
564
569
569
570
571
571
579
581

16. MySQL Enterprise Monitor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
Getting Started with MySQL Enterprise Monitor
Commercial Offerings
Anatomy of MySQL Enterprise Monitor

Installation Overview
MySQL Enterprise Monitor Components
Dashboard
Monitoring Agent

584
585
585
586
590
591
594

Table of Contents

www.it-ebooks.info

|

xi


Advisors
Query Analyzer
MySQL Production Support
Using MySQL Enterprise Monitor
Monitoring
Query Analyzer
Further Information
Conclusion


594
595
597
597
599
605
608
609

17. Managing MySQL Replication with MySQL Utilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
Common MySQL Replication Tasks
Checking Status
Stopping Replication
Adding Slaves
MySQL Utilities
Getting Started
Using the Utilities Without Workbench
Using the Utilities via Workbench
General Utilities
Comparing Databases for Consistency: mysqldbcompare
Copying Databases: mysqldbcopy
Exporting Databases: mysqldbexport
Importing Databases: mysqldbimport
Discovering Differences: mysqldiff
Showing Disk Usage: mysqldiskusage
Checking Tables Indexes: mysqlindexcheck
Searching Metadata: mysqlmetagrep
Searching for Processes: mysqlprocgrep
Cloning Servers: mysqlserverclone

Showing Server Information: mysqlserverinfo
Cloning Users: mysqluserclone
Utilities Client: mysqluc
Replication Utilities
Setting Up Replication: mysqlreplicate
Checking Replication Setup: mysqlrplcheck
Showing Topologies: mysqlrplshow
High Availability Utilities
Concepts
mysqlrpladmin
mysqlfailover
Creating Your Own Utilities
Architecture of MySQL Utilities

xii

|

Table of Contents

www.it-ebooks.info

612
612
615
617
618
618
619
619

621
621
624
625
628
629
632
635
636
637
639
641
642
643
644
644
646
648
650
650
651
655
663
663


Custom Utility Example
Conclusion

664

673

A. Replication Tips and Tricks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
B. A GTID Implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705

Table of Contents

www.it-ebooks.info

|

xiii


www.it-ebooks.info


Foreword for the Second Edition

In 2011, Pinterest started growing. Some say we grew faster than any other startup to
date. In the earliest days, we were up against a new scalability bottleneck every day that
could slow down the site or bring it down altogether. We remember having our laptops
with us everywhere. We slept with them, we ate with them, we went on vacation with
them. We even named them. We have the sound of the SMS outage alerts imprinted in
our brains.
When the infrastructure is constantly being pushed to its limits, you can’t help but wish
for an easy way out. During our growth, we tried no less than five well-known database
technologies that claimed to solve all our problems, but each failed catastrophically.
Except MySQL. The time came around September 2011 to throw all the cards in the air

and let them resettle. We re-architected everything around MySQL, Memcache, and
Redis with just three engineers.
MySQL? Why MySQL? We laid out our biggest concerns with any technology and
started asking the same questions for each. Here’s how MySQL shaped up:
• Does it address our storage needs? Yes, we needed mappings, indexes, sorting, and
blob storage, all available in MySQL.
• Is it commonly used? Can you hire somebody for it? MySQL is one of the most
common database choices in production today. It’s so easy to hire people who have
used MySQL that we could walk outside in Palo Alto and yell out for a MySQL
engineer and a few would come up. Not kidding.
• Is the community active? Very active. There are great books available and a strong
online community.
• How robust is it to failure? Very robust! We’ve never lost any data even in the most
dire of situations.
• How well does it scale? By itself, it does not scale beyond a single box. We’d need a
sharding solution layered on top. (That’s a whole other discussion!)

xv

www.it-ebooks.info


• Will you be the biggest user? Nope, not by far. Bigger users included Facebook,
Twitter, and Google. You don’t want to be the biggest user of a technology if you
can help it. If you are, you’ll trip over new scalability problems that nobody has had
a chance to debug yet.
• How mature is it? Maturity became the real differentiator. Maturity to us is a meas‐
ure of the blood, sweat, and tears that have gone into a program divided by its
complexity. MySQL is reasonably complex, but not nearly so compared to some of
the magic autoclustering NoSQL solutions available. Additionally, MySQL has had

28 years of the best and the brightest contributing back to it from such companies
as Facebook and Google, who use it at massive scale. Of all the technologies we
looked at, by our definition of maturity, MySQL was a clear choice.
• Does it have good debugging tools? As a product matures, you naturally get great
debugging and profiling tools since people are more likely to have been in a similar
sticky situation. You’ll find yourself in trouble at 3 A.M. (multiple times). Being
able to root cause an issue and get back to bed is better than rewriting for another
technology by 6 A.M.
Based on our survey of 10 or so database technologies, MySQL was the clear choice.
MySQL is great, but it kinda drops you off at your destination with no baggage and you
have to fend for yourself. It works very well and you can connect to it, but as soon as
you start using it and scaling, the questions starting flying:
• My query is running slow, now what?
• Should I enable compression? How do I do it?
• What are ways of scaling beyond one box?
• How do I get replication working? How about master-master replication?
• REPLICATION STOPPED! NOW WHAT?!
• What are options for durability (fsync speeds)?
• How big should my buffers be?
• There are a billion fields in mysql.ini. What are they? What should they be set to?
• I just accidentally wrote to my slave! How do I prevent that from happening again?
• How do I prevent running an UPDATE with no where clause?
• What debugging and profiling tools should I be using?
• Should I use InnoDB, MyISAM, or one of several other flavors of storage engine?
The online community is helpful for answering specific questions, finding examples,
bug fixes, and workarounds, but often lacks a strong cohesive story, and deeper dis‐
cussions about architecture are few and far between. We knew how to use MySQL at

xvi


|

Foreword for the Second Edition

www.it-ebooks.info


small scale, but this scale and pace were insane. High Availability MySQL provided
insights that allowed us to squeeze more out of MySQL.
One new feature in MySQL 5.6, Global Transaction Handlers, adds a unique identifier
to every transaction in a replication tree. This new feature makes failover and slave
promotion far easier. We’ve been waiting for this for a long time and it’s well covered in
this new edition.
During our grand re-architecture to a sharded solution, we referred to this book for
architectural decisions, such as replication techniques and topologies, data sharding
alternatives, monitoring options, tuning, and concerns in the cloud. It gave us a deeper
understanding of how MySQL works underneath the hood, which allowed us to make
better informed choices around the high level queries, access patterns, and structures
we’d be using, as well as iterate on our design afterward. The resulting MySQL archi‐
tecture still serves Pinterest’s core data needs today.
—Yashwanth Nelapati and Marty Weiner
Pinterest
February 2014

Foreword for the Second Edition

www.it-ebooks.info

|


xvii


www.it-ebooks.info


Foreword for the First Edition

A lot of research has been done on replication, but most of the resulting concepts are
never put into production. In contrast, MySQL replication is widely deployed but has
never been adequately explained. This book changes that. Things are explained here
that were previously limited to people willing to read a lot of source code and spend a
lot of time—including a few late-night sessions—debugging it in production.
Replication enables you to provide highly available data services while enduring the
inevitable failures. There are an amazing number of ways for things to fail, including
the loss of a disk, server, or data center. Even when hardware is perfect or fully redundant,
people are not. Database tables will be dropped by mistake. Applications will write
incorrect data. Occasional failure is assured. But with reasonable preparation, recovery
from failure can also be assured. The keys to survival are redundancy and backups.
Replication in MySQL supports both.
But MySQL replication is not limited to supporting failure recovery. It is frequently used
to support read scale-out. MySQL can efficiently replicate to a large number of servers.
For applications that are read-mostly, this is a cost-effective strategy for supporting a
large number of queries on commodity hardware.
And there are other interesting uses for MySQL replication. Online data definition lan‐
guage (DDL) is a very complex feature to implement in a relational database manage‐
ment system. MySQL does not support online DDL, but through the use of replication,
you can implement something that is frequently good enough. You can get a lot done
with replication if you are willing to be creative.
Replication is one of the features that made MySQL wildly popular. It is also the feature

that allows you to convert a popular MySQL prototype into a successful business-critical
deployment. Like most of MySQL, replication favors simplicity and ease of use. As a
consequence, it is occasionally less than perfect when running in production. This book
explains what you need to know to successfully use MySQL replication. It will help you
to understand how replication has been implemented, what can go wrong, how to pre‐

xix

www.it-ebooks.info


vent problems, and how to fix them when—despite your best attempts at prevention—
they crop up.
MySQL replication is also a work in progress. Change, like failure, is also assured.
MySQL is responding to that change, and replication continues to get more efficient,
more robust, and more interesting. For instance, row-based replication is new in MySQL
5.1.
While MySQL deployments come in all shapes and sizes, I care most about data services
for Internet applications and am excited about the potential to replicate from MySQL
to distributed storage systems like HBase and Hadoop. This will make MySQL better at
sharing the data center.
I have been on teams that support important MySQL deployments at Facebook and
Google. I’ve encountered many of the problems covered in this book and have had the
opportunity and time to learn solutions. The authors of this book are also experts on
MySQL replication, and by reading this book you can share their expertise.
—Mark Callaghan

xx

|


Foreword for the First Edition

www.it-ebooks.info


Preface

The authors of this book have been creating parts of MySQL and working with it for
many years. Dr. Charles Bell is a senior developer leading the MySQL Utilities team. He
has also worked on replication and backup. His interests include all things MySQL,
database theory, software engineering, microcontrollers, and three-dimensional print‐
ing. Dr. Mats Kindahl is a principal senior software developer currently leading the
MySQL High Availability and Scalability team. He is architect and implementor of sev‐
eral MySQL features. Dr. Lars Thalmann is the development director and technical lead
of the MySQL Replication, Backup, Connectors, and Utilities teams, and has designed
many of the replication and backup features. He has worked on the development of
MySQL clustering, replication, and backup technologies.
We wrote this book to fill a gap we noticed among the many books on MySQL. There
are many excellent books on MySQL, but few that concentrate on its advanced features
and applications, such as high availability, reliability, and maintainability. In this book,
you will find all of these topics and more.
We also wanted to make the reading a bit more interesting by including a running
narrative about a MySQL professional who encounters common requests made by his
boss. In the narrative, you will meet Joel Thomas, who recently decided to take a job
working for a company that has just started using MySQL. You will observe Joel as he
learns his way around MySQL and tackles some of the toughest problems facing MySQL
professionals. We hope you find this aspect of the book entertaining.

Who This Book Is For

This book is for MySQL professionals. We expect you to have basic knowledge of SQL,
MySQL administration, and the operating system you are running. We provide intro‐
ductory information about replication, disaster recovery, system monitoring, and other
key topics of high availability. See Chapter 1 for other books that offer useful background
information.

xxi

www.it-ebooks.info


How This Book Is Organized
This book is divided into two parts. Part I encompasses MySQL high availability and
scale-out. Because these depend a great deal on replication, a lot of this part focuses on
that topic. Part II examines monitoring and performance concerns for building robust
data centers.

Part I, High Availability and Scalability
Chapter 1, Introduction, explains how this book can help you and gives you a context
for reading it.
Chapter 2, MySQL Replicant Library, introduces a Python library for working with sets
of servers that is used throughout the book.
Chapter 3, MySQL Replication Fundamentals, discusses both manual and automated
procedures for setting up basic replication.
Chapter 4, The Binary Log, explains the critical file that ties together replication and
helps in disaster recovery, troubleshooting, and other administrative tasks.
Chapter 5, Replication for High Availability, shows a number of ways to recover from
server failure, including the use of automated scripts.
Chapter 6, MySQL Replication for Scale-Out, shows a number of techniques and top‐
ologies for improving the read scalabilility of large data sets.

Chapter 7, Data Sharding, shows techniques for handling very large databases and/or
improving the write scalability of a database through sharding.
Chapter 8, Replication Deep Dive, addresses a number of topics, such as secure data
transfer and row-based replication.
Chapter 9, MySQL Cluster, shows how to use this tool to achieve high availability.

Part II, Monitoring and Managing
Chapter 10, Getting Started with Monitoring, presents the main operating system pa‐
rameters you have to be aware of, and tools for monitoring them.
Chapter 11, Monitoring MySQL, presents several tools for monitoring database activity
and performance.
Chapter 12, Storage Engine Monitoring, explains some of the parameters you need to
monitor on a more detailed level, focusing on issues specific to MyISAM or InnoDB.
Chapter 13, Replication Monitoring, offers details about how to keep track of what mas‐
ters and slaves are doing.

xxii

|

Preface

www.it-ebooks.info


Chapter 14, Replication Troubleshooting, shows how to deal with failures and restarts,
corruption, and other incidents.
Chapter 15, Protecting Your Investment, explains the use of backups and disaster re‐
covery techniques.
Chapter 16, MySQL Enterprise Monitor, introduces a suite of tools that simplifies many

of the tasks presented in earlier chapters.
Chapter 17, Managing MySQL Replication with MySQL Utilities, introduces the MySQL
Utilities, which are a new set of tools for managing MySQL Servers.

Appendixes
Appendix A, Replication Tips and Tricks, offers a grab bag of procedures that are useful
in certain situations.
Appendix B, A GTID Implementation, shows an implementation for handling failovers
with transactions if you are using servers that don’t support GTIDs.

Conventions Used in This Book
The following typographical conventions are used in this book:
Plain text
Indicates menu titles, table names, options, and buttons.
Italic
Indicates new terms, database names, URLs, email addresses, filenames, and Unix
utilities.
Constant width

Indicates command-line options, variables and other code elements, the contents
of files, and the output from commands.
Constant width bold

Shows commands or other text that should be typed literally by the user.
Constant width italic

Shows text that should be replaced with user-supplied values.
This element signifies a tip or suggestion.

Preface


www.it-ebooks.info

|

xxiii


×