12
The Quick and Easy Guide to Speeding up MySQL For Website Developers

Quick And Easy Guide To Speeding Up MySQL for web developers

Embed Size (px)

DESCRIPTION

A presentation given for PHP West Midlands in March 2009

Citation preview

Page 1: Quick And Easy Guide To Speeding Up MySQL for web developers

The Quick and Easy Guide to Speeding up MySQL

For Website Developers

Page 2: Quick And Easy Guide To Speeding Up MySQL for web developers

The Quick and Easy Guide to Speeding up MySQL

Page 3: Quick And Easy Guide To Speeding Up MySQL for web developers

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.

Page 4: Quick And Easy Guide To Speeding Up MySQL for web developers

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.

Page 5: Quick And Easy Guide To Speeding Up MySQL for web developers

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)

Page 6: Quick And Easy Guide To Speeding Up MySQL for web developers

Choosing the Right Data Type

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

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

Page 7: Quick And Easy Guide To Speeding Up MySQL for web developers

Choosing the Right Storage Engine

MyISAM vs InnoDBTable Locking Vs Row-level LockingMemoryArchiveCSV

Page 8: Quick And Easy Guide To Speeding Up MySQL for web developers

Some MySQL Internals

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

Page 9: Quick And Easy Guide To Speeding Up MySQL for web developers

Replication

Mostly ReadsMaster-Slave

Mostly WritesMaster-Master

BackupsHigh Availability

Page 10: Quick And Easy Guide To Speeding Up MySQL for web developers

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

Page 11: Quick And Easy Guide To Speeding Up MySQL for web developers

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

Page 12: Quick And Easy Guide To Speeding Up MySQL for web developers

The EndQ&A

hope you found the presentation useful