Feb 112010

MySQL Performance Tuning Primer Script

This script takes information from “SHOW STATUS LIKE…” and “SHOW VARIABLES LIKE…”
to produce sane recommendations for tuning server variables.
It is compatible with all versions of MySQL 3.23 and higher (including 5.1).

Currently it handles recommendations for the following:
# Slow Query Log
# Max Connections
# Worker Threads
# Key Buffer
# Query Cache
# Sort Buffer
# Joins
# Temp Tables
# Table (Open & Definition) Cache
# Table Locking
# Table Scans (read_buffer)
# Innodb Status

Recent Changes
# Correct awk display error which formats integers > 4294967296 in scientific notation.
– Was manifest in MEMORY USAGE section where total system RAM > 4GB.
# Fixed rounding error where mysql will lose 4K from the join_buffer_size value.
– Other values may have the same issue but are not yet reported
# Added support for FreeBSD and MacOS (thanks Sam and Geert)
# Added support for Solaris
# Changed how system memory is derived on Linux.
– Use /proc/meminfo vs free -b and avoid inclusion of swap space.
# Include note warning of instability when key_buffer_size > 4GB in versions 5.0.51 and lower

To get the tuning-primer.sh run the following from the command line
wget -O /scripts/tuning-primer.sh http://day32.com/MySQL/tuning-primer.sh
and then execute the script like so

[email protected] [~]# sh /scripts/tuning-primer.sh

- By: Matthew Montgomery -

MySQL Version 5.0.87-community i686

Uptime = 35 days 4 hrs 24 min 23 sec
Avg. qps = 0
Total Questions = 953824
Threads Connected = 1

Server has been running for over 48hrs.
It should be safe to follow these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

The slow query log is NOT enabled.
Current long_query_time = 10 sec.
You have 0 out of 953845 that take longer than 10 sec. to complete
Your long_query_time seems to be fine

The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html

Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine

Current max_connections = 150
Current threads_connected = 1
Historic max_used_connections = 13
The number of used connections is 8% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating

No InnoDB Support Enabled!

Max Memory Ever Allocated : 110 M
Configured Max Per-thread Buffers : 234 M
Configured Max Global Buffers : 90 M
Configured Max Memory Limit : 324 M
Physical Memory : 512 M
Max memory limit seem to be within acceptable norms

Current MyISAM index space = 1 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 326
Key buffer free ratio = 85 %
Your key_buffer_size seems to be fine

Query cache is enabled
Current query_cache_size = 64 M
Current query_cache_used = 715 K
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 1.09 %
Current query_cache_min_res_unit = 4 K
Query Cache is 24 % fragmented
Run "FLUSH QUERY CACHE" periodically to defragment the query cache memory
If you have many small queries lower 'query_cache_min_res_unit' to reduce fragmentation.
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won't cache query results that are larger than query_cache_limit in size

Current sort_buffer_size = 512 K
Current read_rnd_buffer_size = 512 K
Sort buffer seems to be fine

Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

Current open_files_limit = 4096 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

Current table_cache value = 128 tables
You have a total of 81 tables
You have 128 open tables.
Current table_cache hit rate is 26%
, while 100% of your table cache is in use
You should probably increase your table_cache

Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 35543 temp tables, 36% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.

Current read_buffer_size = 256 K
Current table scan ratio = 12 : 1
read_buffer_size seems to be fine

Current Lock Wait ratio = 1 : 1774
You may benefit from selective use of InnoDB.
If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.

From http://day32.com/MySQL/

 Posted by at 2:50 am