开发者

How to monitor MySQL queries

Say I browse a php page, how do I know what database queries are run? I think if I can log all the queries 开发者_StackOverflowto a .txt file that would solve my problem. I tried to log, but failed. I just want to know the queries (sql strings) sent to it.

I'm using WinXP and Apache.


One way to do it is going into your my.cnf configuration file and activate the general log. As hinted is a performance killer, so never activate it in production. For development is perfectly OK, though. On my laptop is on all the time.

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1


Find your mysql log files directory - mine was:

C:\Program Files\MySQL\MySQL Server 5.0\data

Look for the last updated file. Should be NAME OF YOUR COMPUTER.log - that will be your default logfile ** - Mysql is generally shipped with basic logging enabled, IIRC.

Else, as has been said, set up logging in your cnf file and restart the Mysql service.

** Make yourself a shortcut to this file on your desktop, you should be looking at it often.

When the file gets too big, delete it and restart the Mysql service and it'll start a new one with the same name.


just copy and paste the string in mysql_query() into an echo just before the query.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜