I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8037
41179 credits Members referred : 3
« on: Dec 31, 2005, 02:34:14 AM »
These days I am occupied with optimizing the MySQL server, and I can say that I have learned a lot of stuff.
Here is a small tip for developers, about the slow queries.
There is a tool called mysqldumpslow, which can help you find out which queries are executed too slow, so you have to change them, or the indexed of the tables that are used by them.
To use this functionallity of MySQL, first you must be sure that slow queries are logged.
This can be done with two ways :
my.cnf Open your my.cnf file (this is located at /etc/mysql/ in the most unix os) and add this line :
Now the mySQL server will log all the queries that take more than 10 seconds to be executed in the file /var/log/slow-queries.log
At startup Locate the script that starts and restarts the MySQL server ( /etc/init.d/mysql in most unix os ) and locate the line that starts the server. It should be something like :
Now that you have set the mySQL server to log the slow queries you can use this command to check them :
Code:
mysqldumpslow
This tool will provide you with all the queries that run slow to your server, so now you will be able to make all the necessery changes to your SQL statements or your tables structure.
Bellow is the list of parameters for mysqldumpslow :
-v verbose
-d debug
-s=WORD what to sort by (t, at, l, al, r, ar etc)
-r reverse the sort order (largest last instead of first)
-t=NUMBER just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n=NUMBER abstract numbers with at least n digits within names
-g=WORD grep: only consider stmts that include this string
-h=WORD hostname of db server for *-slow.log filename (can be wildcard)
-i=WORD name of server instance (if using mysql.server startup script)