Mysql – CPU,Memory and disk I/O utilization for each query in thesql

MySQLmysql-5.7

How can we identify the exact CPU,Memory and disk I/O, when a query is executed. I am using mysql 5.7.20 community version. I am able to get only cpu details for session level by setting SET profiling=1. How can we identify all these details in global level for all the sessions.

Best Answer

Memory usage -- InnoDB has a common "buffer pool" where it caches blocks. there is no metric for memory usage. On the other hand, you can find out various statistics for all queries over a period of time by watching the STATUS values of Innodb_% grow.

For CPU time, I recommend turning on the "slowlog" with long_query_time=0. That will rapidly fill disk with lots of details about every query, including the elapsed time. Note that "elapsed" is more interesting that CPU vs I/O.

The slowlog gives you the best view into which queries you should work on improving. Perhaps that is what you are really looking for? Use either pt-query-digest or mysqldumpslow -s t to find the few "worst" queries. More discussion: http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog