Mysql – How to identify what is causing unusual high CPU load in MySQL

MySQLmysql-5.7

I have a MySQL 5.7 server that is since recently under very high CPU load, but no clue where this load comes from.

Looking at the MySQL processlist, it does not look like the server is doing much. There are some connections, but nothing heavy or special that could explain the high CPU.

In efforts to improve the situation I have been doing some data cleanup and applying some advice given by the mysqltuner script, but nothing seams to help much.

My last thought are that maybe something is damaged (some tables?) and MySQL is busy in the background, but I dunno if this makes any sense…

So my question is really, how to go about this? Looking at the processlist like everyone is saying, is not giving me the answers I need. Something inside MySQL is definately eating CPU behind the scenes.

PS: This server is quite powerful and there is plenty of RAM and CPU cores, so this is certainly not a hardware limit.

Best Answer

The slowlog. Granted, this picks up on both high CPU and high I/O, but still it will give you what you are looking for.

Suggestions on digesting, etc: http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog

Often the 'cure' is an appropriate composite index.