I've read a lot about MySQL optimisation and I already optimised MySQL about a year ago. Reason for that was a high system load average. I tuned many queries and edited the my.cnf file. Since then everything was fine, system load went down to about 1.0, even when hundreds of users accessed the website at the same time. CPU load averaged about 1% to 3% which made me a happy man.

Last month, I received an e-mail from my provider, regarding a libc security update. I performed the update and rebooted the server (VPS). From that moment the CPU load got immediately to about 30%, even when almost no one was active on the website (I performed the update early in the morning). I didn't notice this until a few days ago. I've been looking for many hours now, but I can't find the problem.

When I run mysqltuner.pl and tuning-primer.pl everything seems fine, except for a few things. Here are the contents of mysqltuner.pl:

 >>  MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.34-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 101M (Tables: 57)
[--] Data in InnoDB tables: 24M (Tables: 60)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 62

-------- Security Recommendations  -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 23h 53m 22s (153M q [893.221 qps], 870K conn, TX: 244B, RX: 13B)
[--] Reads / Writes: 99% / 1%
[--] Total buffers: 1.6G global + 4.6M per thread (500 max threads)
[OK] Maximum possible memory usage: 3.9G (50% of installed RAM)
[OK] Slow queries: 0% (1K/153M)
[OK] Highest usage of available connections: 54% (272/500)
[OK] Key buffer size / total MyISAM indexes: 1.0G/155.7M
[OK] Key buffer hit rate: 100.0% (20B cached / 422K reads)
[OK] Query cache efficiency: 84.6% (127M cached / 151M selects)
[!!] Query cache prunes per day: 2842572
[OK] Sorts requiring temporary tables: 0% (13K temp sorts / 2M sorts)
[OK] Temporary tables created on disk: 0% (14K on disk / 1M total)
[OK] Thread cache hit rate: 99% (272 created / 870K connections)
[!!] Table cache hit rate: 5% (213 open / 4K opened)
[OK] Open file limit used: 1% (214/16K)
[OK] Table locks acquired immediately: 99% (23M immediate / 23M locks)
[OK] InnoDB data size / buffer pool: 24.3M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Increasing the query_cache size over 128M may reduce performance
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    query_cache_size (> 256M) [see warning above]
    table_cache (> 8192)

I notice some warnings at the cache prunes and table cache sections. I tried to look into this, but these 'problems' seemed to be already existing before the change in CPU usage.

Here's the output of tuning-primer.sh:

MySQL Version 5.5.34-log x86_64

Uptime = 1 days 23 hrs 57 min 1 sec
Avg. qps = 893
Total Questions = 154172359
Threads Connected = 2

Warning: Server has not been running for at least 48hrs.
It may not be safe to use 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 enabled.
Current long_query_time = 2.000000 sec.
You have 1227 out of 154172380 that take longer than 2.000000 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.5/en/point-in-time-recovery.html

Current thread_cache_size = 100
Current threads_cached = 99
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

Current max_connections = 500
Current threads_connected = 1
Historic max_used_connections = 272
The number of used connections is 54% of the configured maximum.
Your max_connections variable seems to be fine.

Current InnoDB index space = 1 M
Current InnoDB data space = 24 M
Current InnoDB buffer pool free = 59 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

Max Memory Ever Allocated : 2.61 G
Configured Max Per-thread Buffers : 2.25 G
Configured Max Global Buffers : 1.39 G
Configured Max Memory Limit : 3.64 G
Physical Memory : 7.76 G
Max memory limit seem to be within acceptable norms

Current MyISAM index space = 155 M
Current key_buffer_size = 1.00 G
Key cache miss rate is 1 : 49320
Key buffer free ratio = 78 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

Query cache is enabled
Current query_cache_size = 256 M
Current query_cache_used = 90 M
Current query_cache_limit = 8 M
Current Query cache Memory fill ratio = 35.46 %
Current query_cache_min_res_unit = 4 K
Query Cache is 25 % 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.
MySQL won't cache query results that are larger than query_cache_limit in size

Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

Current join_buffer_size = 132.00 K
You have had 36 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accommodate larger joins in one pass.

Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.

Current open_files_limit = 16894 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_open_cache = 8192 tables
Current table_definition_cache = 400 tables
You have a total of 158 tables
You have 213 open tables.
The table_cache value seems to be fine

Current max_heap_table_size = 256 M
Current tmp_table_size = 256 M
Of 1538532 temp tables, 0% were created on disk
Created disk tmp tables ratio seems fine

Current read_buffer_size = 2 M
Current table scan ratio = 4270 : 1
You have a high ratio of sequential access requests to SELECTs
You may benefit from raising read_buffer_size and/or improving your use of indexes.

Current Lock Wait ratio = 1 : 3430
You may benefit from selective use of InnoDB.
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=ALWAYS'.

Again, most values seem fine. Nothing serious I think. I didn't change any queries in the last weeks, so I really don't know where the CPU usage suddenly comes from.

Finally, the contents of my.cnf:


#thread_concurrency = 4
log_slow_queries = /var/log/mysql-slow.log
long_query_time = 2
ft_min_word_len = 2
ft_stopword_file = ''
basedir = '/usr'
datadir = '/var/lib/mysql'

Hopefully someone knows what this could be and how to fix it. The queries haven't changed, the MySQL version hasn't changed, the only thing that changed was a system reboot after a libc-update..

Best regards,


  • I forgot to mention: even when there are no queries ran the load is quite high, around 20% cpu caused by MySQL. I know this, because some time ago I had to put the website into maintenance mode and during this hour (in which i performed maintenance regarding front-end stuff) the cpu usage was still high.. – Kaas Feb 23 '15 at 18:42
  • At 900 queries per second, we need to dig deeper into what you are doing. – Rick James Jun 22 '19 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.