Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I see the last queries for a MySQL DB?

I am a DB administrator. For example, when an application queries the DB, how they can be viewed?

share|improve this question

migrated from Mar 5 '10 at 23:15

This question came from our site for professional and enthusiast programmers.

On a development database, you can enable the query log:

mysqld_safe --log &

This will create a log in the data directory with your machine's hostname. If you then do something like tail -f on the log (at least in the Unix world, not sure about Windows), you'll be able to see the queries as they are happening.

I said "development," because I don't think there is a way to do this in the production system that won't cause production to come to a halt.

share|improve this answer
You can run it on a production server for debugging if you don't have a development environment. It all depends on how busy the server is and how much room you can spare for the log. If you're only running it for a short period or longer on a quiet database it should be fine. I don't see that enabling the log necessarily leads to the production server coming to a halt. – Richard Holloway Mar 6 '10 at 0:02

You can enable the query log as mentioned. If you want to log particular messages on a system under development you could run the development system through the mysql proxy. Basically it is a service that can sit between the mysql server and client(s). There are many code samples about how to log or manipulate data based on criteria you set.

share|improve this answer
+1 for mentioning MySQL Proxy. – joschi Mar 6 '10 at 8:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.