This document provides a quick guide to speeding up MySQL for website developers, covering topics such as monitoring MySQL performance, choosing the right data types and storage engines, understanding some MySQL internals like key buffers and query caches, using replication for reads and writes, and improving application performance through techniques like de-normalizing data, caching query results, and storing more data instead of logic in the database. The goal is to help developers optimize MySQL so that it works better for their applications with only basic tuning when necessary.
3. Introduction
Presentation for developers who only
tune up MySQL when they really have to.
Basic steps and good practices for using
and speeding up MySQL - so that
MySQL will work better for you.
4. Introduction
90% of the reasons why MySQL is slow
is due to bad schema design.. or in other
words how the database is setup vs how
you use it.
MySQL is fast. No really, it is. It just
needs some attention every now and
then.
5. Monitoring
We use Nagios to monitor MySQL. Some
examples..
What you can't measure, you can't
improve
EXPLAIN SELECT. Some examples..
Benchmarking
Whole application or some scripts?
Profiling (and slowlog)
6. Choosing the Right Data Type
Int/Decimal/Char/Varchar/.....
Text/BLOB
Enum/Set
DateTime /Timestamp
(..update current_timestamp)
Unsigned/Signed
Null/Not Null
Procedure Analyse()
7. Choosing the Right Storage Engine
MyISAM vs InnoDB
Table Locking Vs Row-level Locking
Memory
Archive
CSV
8. Some MySQL Internals
Key Buffer
Innodb Buffer Pool Size
Query Cache
Thread Cache
Temp Tables (Memory Vs on-Disk)
Optimize tables
Partitioning (MySQL 5.1)
10. Application Side Improvements
Storing Duplicate Data
De-normalize
Stored Results (Summary/Cache Table)
Count() in its own Table
Stored Conditions
Stored Reports
Involving the database much more with
your application
11. Application Side Improvements
Unix Philosophy - Rule of Representation
quot;Fold knowledge into data, so program logic can be stupid
and robust.quot;
quot;Even the simplest procedural logic is hard for humans to
verify, but quite complex data structures are fairly easy
to model and reason about.quot;
John Bently
12. The End
Q&A
hope you found
the presentation useful