How to log query and its execution time of each query which runs on a db?
Asked Answered
S

2

11

I have a huge database with more than 250 tables. Different type of queries are ran on the database. Since the database has grown over the years and now I need to optimise the database and queries. I have already followed optimisation concepts such as indexing and so on.

My problem is, How to log the query and its execution time of each query which runs on the database ? So I can analyse which query takes how many seconds and optimise them.

Given that I know that MYSQL Trigger would be ideal for this but I don't know how to write a trigger for the whole database, so that it logs each query to a table with query's execution time. I want the trigger to log all the CRUD operation which occurred in the database.

How can I get it done ?

Sender answered 23/4, 2013 at 7:31 Comment(1)
#6479607Sender
S
13

Use mysql slow query log. This will help you to get only queries which are slow instead of log / analyze all queries. You just need to set param for long_query_time like 1 or 2 second.

Subject answered 23/4, 2013 at 11:58 Comment(0)
W
9

Also you could set long_query_time = 0 and you will see all sql queries!

Wite answered 13/8, 2018 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.