How can i log which all query is executed,how many secs a MYSQL query take to execute, to increase performance of database? I am using PHP
4
-
1Maybe you want to check which query is the slowest try the mysql slow query log to enable this use mysqld --log-slow-queries[=file_name] It will log on a file the slow queriesGerard Banasig– Gerard Banasig2010-09-16 09:12:27 +00:00Commented Sep 16, 2010 at 9:12
-
1Create a wrapper function to handle all queries, that way you can time each on and save it to a log.Ben Everard– Ben Everard2010-09-16 09:13:46 +00:00Commented Sep 16, 2010 at 9:13
-
Let me do a search for you: stackoverflow.com/search?tab=votes&q=[mysql]%20performancefabrik– fabrik2010-09-16 09:29:01 +00:00Commented Sep 16, 2010 at 9:29
-
I ran the above command in a console and executed my app frm browser, but nothing is logged :( What to do?Ron Davis– Ron Davis2010-09-16 11:49:34 +00:00Commented Sep 16, 2010 at 11:49
Add a comment
|
1 Answer
Use the slow query log for catching queries which run longer than a specified time limit (2 seconds by default). This will show you the worst offenders; probably many will be low-hanging fruit, fixable by proper indexes.
It won't catch a different type of code smell: a relatively fast query running many times in a tight loop.
If you wish, you may set the slow query limit to 0 and it will log all queries - note that this in itself will slow down the server.
4 Comments
Ron Davis
I ran the above command in a console and executed my app frm browser, but nothing is logged :( What to do?
Piskvor left the building
@Ashwin: A better option is to change the settings in your MySQL configuration file. If no slow queries are logged, it means you don't have any queries running longer than the specified time - do you actually have a measurable performance problem? As I said, you could set the slow query limit to 0 in your config, but that amount of logging may slow down the server.
Ron Davis
yeah did that nothing is logged, but when i gave log-queries-not-using-indexes
Piskvor left the building
@Ashwin: You don't seem to have any slow queries, then :) Congratulations.