Search with keywords, i.e., table names or column names.
While using your mobile app or a web application or a desktop application, you will know what page is taking more than expected time to load. Many-a-times, load time is impacted by the queries that run in the background. But that is only when we are making sync calls rather than async calls to fetch the data. So, when you know the page/area which is loading slowly, you will have a list of queries that run on that page while loading and a list of queries that are fired because you perform an action on that page. Once you know the queries, you will know the tables being used and the columns being fetched.
Now, if you are searching the slow query log and you have set very high standards for yourself and set the slow query time to 400 milliseconds, there are chances that your slow query log will be loaded, unless you are a genius. So, we do this simple thing:
grep 'table_name' /var/lib/mysql/mysql-slow.log
This poses more problems than it solves because all the important questions remain unanswered as this doesn't give the query time, query date etc. So, do this:
grep -B 3 'table_name' /var/lib/mysql/mysql-slow.log
-B x gives you x number of lines before the query.
We would need this because the 3 lines prior to the actual query contain all the information about the execution of the query - when was the query executed and how much time did it take!
An alternate:
grep -A 3 'query_user' /var/lib/mysql/mysql-slow.log
Number of slow queries during the day, hour-wise
grep Time mysql-slow.log | cut -d: -f1,2 | sort -r | uniq -c
A note here: you can either use sort -u or you can use sort | uniq -c but be sure that uniq won't work independently, it will only work when you pipe it with sort. Sorting should be done prior to uniq.
Using mysqldumpslow to analyse the log
Getting the top 10 underperforming queries.
mysqldumpslow -u root -p -s c -t 10
If you need to get into detailed log analytics, you should set up the ELK stack on your machine and connect your mysql to the log analytics setup. Or, you can use NewRelic for analysing MySQL logs.