Mysql – How to Check and Report time taking queries

MySQLmysql-5.6optimizationperformancequery-performance

I am using MySQL 5.6.24

How do I capture the queries which are using more system resources?

How do I capture slow running queries and queries not using indexes?

What is the best way to optimize the slow running query?

Thanks in advance

Best Answer

To capture the slow running queries in MySQL, please enable slow query log. Refer the below URL:

http://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html

To optimize the queries, you need to get the explain plan of the queries using EXPLAIN command:

EXPLAIN SELECT * FROM categories

Detailed documentation is available in the below URL:

https://www.sitepoint.com/using-explain-to-write-better-mysql-queries/