开发者

how to check log in mysql

How would i monitor a MySQL to detect SELECTs which are running slowly? Having identified a poorly performing SELECT, how wo开发者_运维问答uld i analyse it with a view to improving it?


You would enable slow query logging, e.g. add this to your my.cnf under the [mysqld] section

set-variable=slow_query_log=on
set-variable=long_query_time=20

This will log all queries taking 20 seconds or more to a "hostname"-slow.log, e.g. /var/lib/mysql/localhost-slow.log

You'd then inspect those queries, and at least run EXPLAIN on them, and figure out what makes it slow, e.g. add indexes, rewrite the SQL etc. - though optimizing queries is a whole other book.


MySQL keeps a 'slow query log' which will provide you with information about slow running queries.

I think it's enabled by default, and its location is set in your MySQL .ini file.

See here for more information on the slow query log.

You can use EXPLAIN to get information about how MySQL is executing your queries - just put EXPLAIN before your query. There is a good article here on how to interpret the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜