2

Say I browse a php page, how do I know what database queries are run? I think if I can log all the queries to 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.

4
  • what you want to know??? where is code?? Commented Oct 4, 2011 at 13:36
  • 2
    @diEcho code is not relevant, he wants to see the query log Commented Oct 4, 2011 at 13:37
  • 1
    @Ben: edit not comment Commented Oct 4, 2011 at 13:41
  • @WesleyMurch Fair point, usually would... Commented Oct 4, 2011 at 13:48

3 Answers 3

9

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
Sign up to request clarification or add additional context in comments.

1 Comment

Once this configuration is done, a mysql restart is required. Or, as it's mentioned, you can temporarily enable the log at runtime: Just run the mysql query: "SET global general_log = 'ON';" Then your general_log_file will log all queries.
0

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.

2 Comments

mine mysql5.1 — I can not find the dir named "data"
Searching your hdd for a folder called /data could be long and slow.
-4

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

1 Comment

because this is kind of manually way, can be use only when you typing those codes, can not use it for some large existing code where you need to know which queries has run. Also mysql already has a configuration for this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.