2

Is it possible to log all queries that are executed? I am looking at a database that is accessed by many different apps. One of them is modifying a table's value in a way it should not. I am trying figure out which app is the culprit. It would help me out a lot if I can capture all the queries that are executed on that table and at what time.

Many thanks in advance for your help.

1
  • what is the best place to put the my.cnf and how do i tell MAMP where this file is? so that it will work. beccause no matter what i do nothing gets logged. i am using mac with MAMP its like wamp on windows. Commented Aug 2, 2011 at 22:57

6 Answers 6

1

Either use the --log[=file_name] command line switch on mysqld or edit/create a my.cnf containing:

[mysqld]
log=/tmp/mysql.log

Explained fully in this article.

Sign up to request clarification or add additional context in comments.

Comments

0

As far as I am aware, there are currently no auditing capabilities built in to MySQL. Log queries from within the applications that generate them, or sniff connections to the server.

3 Comments

Please leave a comment with your downvote. What is wrong with my answer? Thanks.
@Sarmen: Please direct us to the documentation for this feature. If it exists, then I will happily delete/edit my answer. Otherwise, please remove your downvote. Either way, downvotes are best accompanied by explanations. Thanks.
The general query log, which for whatever reason I did not spot eight months ago, might be appropriate here.
0

in your .ini configuration add this line

log=allqueries.log

you will need to restart mysql

Comments

0

A possible solution to your problem is to utilize an update trigger on the table in question. The trigger will be fired on any update to the table, and it possible to write the trigger such that when it meets certain criteria (the value in question is changed), an action is performed (perhaps writing to a temporary table, the SQL statement that makes the change). For more information, I suggest looking at Trigger Syntax.

Comments

0

Take a look here: http://dev.mysql.com/doc/refman/5.1/en/server-logs.html You're looking for general query log: http://dev.mysql.com/doc/refman/5.1/en/query-log.html

Comments

0

You can use the general log in MySQL to achieve this. I only recommend you do that on a test/development database without many concurrent users, because the amount of output generated is huge. I'm not sure if it logs the timestamp, though.

If it doesn't, on a unix/linux setup, I'd say write a simple script that read lines from the stdin and print the lines with the current timestamp when they were read, and pipe tail -f on the log file to it, so you can add your own timestamps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.