SlideShare a Scribd company logo
<Insert Picture Here>

Troubleshooting MySQL Performance
Sveta Smirnova
Principal Technical MySQL Support Engineer
What will we discuss

• Workflow
–Missed details
• http://www.sql-error.js-client.com/devconf2012
•

http://www.microbecal.com/ftp_load/Troubleshooting_MySQL_Performance_addons_en.pdf

•

http://www.slideshare.net/SvetaSmirnova/troubleshooting-my-sqlperformanceaddonsen
What are we going to troubleshoot?

• What does mean slowly?
• It depends
• Think about your application
How to find if MySQL is a weak link?
• Pseudo-code
–
–
–
–

Measure current time at moment1
Call MySQL function
Measure current time at moment2
Difference between moment2 and moment1 is how much
time MySQL spent working on your request.

• Usually built-in into software you use
• Only rough imagination needed
What to check

• Query
• Options
• Hardware
Sandbox
• Test!
• But testing in production is dangerous!
• Copy data
– CREATE TABLE test_copy LIKE test;
– INSERT INTO test_copy SELECT * FROM test;
– Any backup-restore technique which can copy-restore single
table

• OR
– CREATE DATABASE test_copy;
– Copy all involved objects (tables, views and so on) into new
database
– Use your favorite backup-restore technique
MySQL Sandbox
• Designed by Giuseppe Maxia to create MySQL
Sandbox of distribution you like with single command
• Available at http://mysqlsandbox.net/
• Collection of Perl scripts
• On UNIX, Linux, Mac OS X
–
–
–
–

perl Makefile.PL
make
[make test] - optionally
sudo make install

• Use Cygwin on Windows
• Need mysql-*.tar.gz or mysql-*.zip package
How to find out if query runs slow?

• At development stage
• On production only
–EXPLAIN
–Slow query log
What to do next?

• EXPLAIN
• EXPLAIN EXTENDED
• EXPLAIN PARTITIONS
• SHOW STATUS LIKE 'Handler_%'
Suddenly slow query
• Worked fast initially
• Diagnostic utilities showed good result
• After some time, usually long, started to work slow
– Variance: works fast on development server and slow on
production

• Stable slowdown: it never works fast anymore
• How to find:
– Slow Query Log
– SHOW PROCESSLIST

• How to fix:
– Same methods like for simple slow query
– Data and index file maintaining
SHOW PROCESSLIST
Your first friend when debugging
Shows all queries, executing at the moment
Accessible in any version
You can find same data in the
INFORMATION_SCHEMA.PROCESSLIST table,
introduced in version 5.1
• Only tool for MyISAM
• MDL locks are also visible in
•
•
•
•

– performance_schema.event_waits
Parallel execution: InnoDB

• SHOW ENGINE INNODB STATUS
• INNODB_* tables
in the
INFORMATION SCHEMA
–INNODB_TRX
–INNODB_LOCKS
–INNODB_LOCK_WAITS
General Query Log
●
●
●
●
●
●
●
●
●
●

mysql> select * from mysql.general_log where
thread_id = 1312 order by event_time G
******************* 1. row *******************
  event_time: 2009­10­01 15:54:11
   user_host: root[root] @ localhost []
   thread_id: 1312
   server_id: 51
command_type: Query
    argument: begin

●
●
●
●
●
●
●
●
●
●

******************* 2. row *******************
  event_time: 2009­10­01 15:54:13
   user_host: root[root] @ localhost []
   thread_id: 1312
   server_id: 51
command_type: Query
    argument: insert into t1 values(2,'1994­12­30',
'1994­12­03')
2 rows in set (0.12 sec)  
MySQL Server Variables or Options: Scope

§ Global
– Control parameters, necessary for all server processes

Location of server files: datadir etc.
– Shared buffers
– More
§ Session
– Control connection-specific parameters
–
MySQL Server Variables or Options:
When allocated

§ Those which control behavior of whole server
– Once at server startup

Can start with low values, then grow to specified
§ Connection options
– For every connection when connection opens
§ Operation-specific
– For every operation when needed
–
MySQL Server Variables or Options:
How to control

§ SHOW [GLOBAL] STATUS
§ GLOBAL
– Since server start
§ SESSION
– For operations in current session
– Can be reset
–

FLUSH STATUS
MySQL Server Variables or Options:
When affecting option is not known

§ Record currently used variables
– SHOW [GLOBAL] VARIABLES
§ Start mysqld with option –no-defaults
– This option must be first one!
§ Check if problem is solved
§ Change variable values one-by-one until you find one

which leads to the problem
System resources

• Memory
• CPU
• Disk
• Network
Memory: diagnostic
• Free
–
–
–
–
–

[sveta@delly meb-trunk]$ free
total
used
free shared buffers cached
Mem:
7937924 7665236 272688
0 708056 5079376
-/+ buffers/cache: 1877804 6060120
Swap:
8546572
6200 8540372

• Top
–
–
–
–

Tasks: 246 total,
2 running, 244 sleeping,
0 stopped,
0 zombie
Cpu(s): 3.2%us, 1.2%sy, 0.0%ni, 95.1%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem:
7937924k total, 7662172k used,
275752k free,
708148k buffers
Swap: 8546572k total,
6200k used, 8540372k free, 5075036k cached

–
–

PID USER

PR

NI

VIRT

RES

–

1914 mysql

20

0

670m

95m 1296 S

• vmstat

SHR S %CPU %MEM
0.7

1.2

TIME+

COMMAND

2:42.14 mysqld
Disk: diagnostic
• df
–
–
–
–
–
–

[sveta@delly mysql-5.1]$ df
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/sda3
126388036 90639344 29328520 76% /
tmpfs
3968960
672
3968288
1% /dev/shm
/dev/sda2
341869564 114894920 226974644 34% /mnt/windows
/dev/mmcblk0p1
31154688
309376 30845312
1% /media/MYDATA

• iostat
–
–
–
–
–
–
–
–

[sveta@delly mysql-5.1]$ iostat -x
Linux 2.6.32-131.0.15.el6.x86_64 (delly)
05/03/2012
_x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
5.29 0.00
1.47
2.45
0.00 90.79
Device:
rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
Scd0
2.91
0.00
0.09 0.00 11.99
0.00 129.97 0.00
46.46 24.55 0.23
sda
1.43
56.87
2.10 2.39 201.15 473.77 150.25 0.49
109.38 4.83 2.17
mmcblk0
0.03
0.00
0.00 0.00 0.03
0.00 31.08 0.00
3.14 2.69 0.00
CPU: diagnostic
• top
–
–
–
–

Tasks: 246 total,
2 running, 244 sleeping,
0 stopped,
0 zombie
Cpu(s): 3.2%us, 1.2%sy, 0.0%ni, 95.1%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem:
7937924k total, 7662172k used,
275752k free,
708148k buffers
Swap: 8546572k total,
6200k used, 8540372k free, 5075036k cached

–

PID USER

PR

NI

VIRT

RES

SHR S %CPU %MEM

–

1914 mysql

20

0

670m

95m 1296 S

0.7

1.2

TIME+

COMMAND

2:42.14 mysqld

• iostat
• ps
– [sveta@delly src]$ ps -eo pid,user,comm,pcpu,pmem,vsz | grep mysqld
mysqld_safe
0.0 0.0 108192
– 1817 root
mysqld
0.0 1.1 686328
– 1914 mysql
mysqld
0.0 0.5 735744
– 14231 sveta
Network
• Important:
– Stability
– Bandwidth
– Speed
• RTT
• --log-warnings=2
• Send huge file (1G or larger)
• tcpdump
Replication slowdowns
• Slow network
– Any general diagnostic tool
– Connect with mysql command line client
• REPLICATION SLAVE
• Binary log slowdowns master
– InnoDB locks

• Slave is slower than master
– Multi threaded slave
– Tune buffers
– SHOW SLAVE STATUS
• Seconds_behind_master
References
•
•
•
•
•
•

http://dev.mysql.com/doc/refman/5.5/en/index.html
http://shop.oreilly.com/product/0636920021964.do
http://shop.oreilly.com/product/0636920022343.do
http://planet.mysql.com/
http://www.mysqlperformanceblog.com/
http://dimitrik.free.fr/blog/index.html
Summary
• Tune queries
– Check if query is always slow
– Ensure query is not affected by concurrency issue

•
•
•
•

Check if your options are sane
Check your hardware and operating system
Repeat until you are happy
Don't overtune!
THANK YOU!
?
The preceding is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.

More Related Content

What's hot (20)

PDF
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
PDF
MySQL Query tuning 101
Sveta Smirnova
 
PDF
Basic MySQL Troubleshooting for Oracle DBAs
Sveta Smirnova
 
PDF
UKOUG 2011: Practical MySQL Tuning
FromDual GmbH
 
PDF
MySQL Performance Schema in Action
Sveta Smirnova
 
PDF
Preparse Query Rewrite Plugins
Sveta Smirnova
 
PDF
Character Encoding - MySQL DevRoom - FOSDEM 2015
mushupl
 
PDF
Performance Schema for MySQL troubleshooting
Sveta Smirnova
 
PDF
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
PDF
MySQL Troubleshooting with the Performance Schema
Sveta Smirnova
 
PDF
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
PDF
Introduction to MySQL Query Tuning for Dev[Op]s
Sveta Smirnova
 
PDF
Summary tables with flexviews
Justin Swanhart
 
PDF
Introduction into MySQL Query Tuning
Sveta Smirnova
 
PDF
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
PDF
Highload Perf Tuning
HighLoad2009
 
PDF
Noinject
Justin Swanhart
 
PDF
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk
 
PDF
Introduction into MySQL Query Tuning for Dev[Op]s
Sveta Smirnova
 
PDF
Flexviews materialized views for my sql
Justin Swanhart
 
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
MySQL Query tuning 101
Sveta Smirnova
 
Basic MySQL Troubleshooting for Oracle DBAs
Sveta Smirnova
 
UKOUG 2011: Practical MySQL Tuning
FromDual GmbH
 
MySQL Performance Schema in Action
Sveta Smirnova
 
Preparse Query Rewrite Plugins
Sveta Smirnova
 
Character Encoding - MySQL DevRoom - FOSDEM 2015
mushupl
 
Performance Schema for MySQL troubleshooting
Sveta Smirnova
 
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
MySQL Troubleshooting with the Performance Schema
Sveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Introduction to MySQL Query Tuning for Dev[Op]s
Sveta Smirnova
 
Summary tables with flexviews
Justin Swanhart
 
Introduction into MySQL Query Tuning
Sveta Smirnova
 
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
Highload Perf Tuning
HighLoad2009
 
Noinject
Justin Swanhart
 
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk
 
Introduction into MySQL Query Tuning for Dev[Op]s
Sveta Smirnova
 
Flexviews materialized views for my sql
Justin Swanhart
 

Similar to Troubleshooting MySQL Performance (20)

PPTX
Percona Live UK 2014 Part III
Alkin Tezuysal
 
PDF
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
PDF
The MySQL SYS Schema
Mark Leith
 
PDF
Monitoreo de MySQL y PostgreSQL con SQL
Emanuel Calvo
 
PDF
MySQL performance webinar
Abel Flórez
 
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
PDF
Mysql tech day_paris_ps_and_sys
Mark Leith
 
KEY
Tek tutorial
Ligaya Turmelle
 
PDF
MySQL Performance Schema in Action
Sveta Smirnova
 
ODP
MySQL Monitoring Mechanisms
Mark Leith
 
ODP
MySQL Monitoring Mechanisms
Mark Leith
 
PDF
MySQL Performance Schema in Action: the Complete Tutorial
Sveta Smirnova
 
PDF
MySQL's Performance Schema, SYS Schema and Workbench Integration
Mario Beck
 
PPT
MySQL Performance Tuning at COSCUP 2014
Ryusuke Kajiyama
 
DOCX
Performence tuning
Vasudeva Rao
 
KEY
DPC Tutorial
Ligaya Turmelle
 
ODP
Performance Tuning
Ligaya Turmelle
 
PDF
Mysql tracing
Anis Berejeb
 
PDF
Mysql tracing
Anis Berejeb
 
PPT
MySQL 5.7: Performance Schema Improvements
Mark Leith
 
Percona Live UK 2014 Part III
Alkin Tezuysal
 
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
The MySQL SYS Schema
Mark Leith
 
Monitoreo de MySQL y PostgreSQL con SQL
Emanuel Calvo
 
MySQL performance webinar
Abel Flórez
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
Mysql tech day_paris_ps_and_sys
Mark Leith
 
Tek tutorial
Ligaya Turmelle
 
MySQL Performance Schema in Action
Sveta Smirnova
 
MySQL Monitoring Mechanisms
Mark Leith
 
MySQL Monitoring Mechanisms
Mark Leith
 
MySQL Performance Schema in Action: the Complete Tutorial
Sveta Smirnova
 
MySQL's Performance Schema, SYS Schema and Workbench Integration
Mario Beck
 
MySQL Performance Tuning at COSCUP 2014
Ryusuke Kajiyama
 
Performence tuning
Vasudeva Rao
 
DPC Tutorial
Ligaya Turmelle
 
Performance Tuning
Ligaya Turmelle
 
Mysql tracing
Anis Berejeb
 
Mysql tracing
Anis Berejeb
 
MySQL 5.7: Performance Schema Improvements
Mark Leith
 
Ad

More from Sveta Smirnova (20)

PDF
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
PDF
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
Sveta Smirnova
 
PDF
Database in Kubernetes: Diagnostics and Monitoring
Sveta Smirnova
 
PDF
MySQL Database Monitoring: Must, Good and Nice to Have
Sveta Smirnova
 
PDF
MySQL Cookbook: Recipes for Developers
Sveta Smirnova
 
PDF
MySQL Performance for DevOps
Sveta Smirnova
 
PDF
MySQL Test Framework для поддержки клиентов и верификации багов
Sveta Smirnova
 
PDF
MySQL Cookbook: Recipes for Your Business
Sveta Smirnova
 
PDF
Производительность MySQL для DevOps
Sveta Smirnova
 
PDF
MySQL Performance for DevOps
Sveta Smirnova
 
PDF
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
Sveta Smirnova
 
PDF
How to migrate from MySQL to MariaDB without tears
Sveta Smirnova
 
PDF
Modern solutions for modern database load: improvements in the latest MariaDB...
Sveta Smirnova
 
PDF
How Safe is Asynchronous Master-Master Setup?
Sveta Smirnova
 
PDF
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Sveta Smirnova
 
PDF
How to Avoid Pitfalls in Schema Upgrade with Galera
Sveta Smirnova
 
PDF
How Safe is Asynchronous Master-Master Setup?
Sveta Smirnova
 
PDF
Billion Goods in Few Categories: How Histograms Save a Life?
Sveta Smirnova
 
PDF
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
Sveta Smirnova
 
PDF
Что нужно знать о трёх топовых фичах MySQL
Sveta Smirnova
 
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
Sveta Smirnova
 
Database in Kubernetes: Diagnostics and Monitoring
Sveta Smirnova
 
MySQL Database Monitoring: Must, Good and Nice to Have
Sveta Smirnova
 
MySQL Cookbook: Recipes for Developers
Sveta Smirnova
 
MySQL Performance for DevOps
Sveta Smirnova
 
MySQL Test Framework для поддержки клиентов и верификации багов
Sveta Smirnova
 
MySQL Cookbook: Recipes for Your Business
Sveta Smirnova
 
Производительность MySQL для DevOps
Sveta Smirnova
 
MySQL Performance for DevOps
Sveta Smirnova
 
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
Sveta Smirnova
 
How to migrate from MySQL to MariaDB without tears
Sveta Smirnova
 
Modern solutions for modern database load: improvements in the latest MariaDB...
Sveta Smirnova
 
How Safe is Asynchronous Master-Master Setup?
Sveta Smirnova
 
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Sveta Smirnova
 
How to Avoid Pitfalls in Schema Upgrade with Galera
Sveta Smirnova
 
How Safe is Asynchronous Master-Master Setup?
Sveta Smirnova
 
Billion Goods in Few Categories: How Histograms Save a Life?
Sveta Smirnova
 
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
Sveta Smirnova
 
Что нужно знать о трёх топовых фичах MySQL
Sveta Smirnova
 
Ad

Recently uploaded (20)

PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 

Troubleshooting MySQL Performance