Quick And Easy Guide To Speeding Up MySQL for web developers

Preview:

DESCRIPTION

A presentation given for PHP West Midlands in March 2009

Citation preview

The Quick and Easy Guide to Speeding up MySQL

For Website Developers

The Quick and Easy Guide to Speeding up MySQL

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.

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.

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)

Choosing the Right Data Type

Int/Decimal/Char/Varchar/.....Text/BLOBEnum/SetDateTime /Timestamp 

(..update current_timestamp)Unsigned/SignedNull/Not NullProcedure Analyse()

Choosing the Right Storage Engine

MyISAM vs InnoDBTable Locking Vs Row-level LockingMemoryArchiveCSV

Some MySQL Internals

Key BufferInnodb Buffer Pool SizeQuery CacheThread CacheTemp Tables (Memory Vs on-Disk)Optimize tablesPartitioning (MySQL 5.1)

Replication

Mostly ReadsMaster-Slave

Mostly WritesMaster-Master

BackupsHigh Availability

Application Side Improvements

Storing Duplicate DataDe-normalize

Stored Results (Summary/Cache Table)Count() in its own Table

Stored ConditionsStored ReportsInvolving the database much more with your application

Application Side Improvements

Unix Philosophy - Rule of Representation"Fold knowledge into data, so program logic can be stupid and robust.""Even the simplest procedural logic is hard for humans to verify, but quite complex data structures are fairly easy to model and reason about."

John Bently

The EndQ&A

hope you found the presentation useful

Recommended