Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 stackoverflow.com Mar 5 '10 at 23:15

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

2 Answers 2

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

 
discard

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.