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

It was decided that we should move to using a (MySQL) database for our application logs (it is a Java app using the logback lib). I am hoping to find something like tail -f that I can use with a specific table in that database that will show me new rows as they are added (similar to how tail -f worked on log files).

share|improve this question
up vote 3 down vote accepted

Turn on MySQL binary logging. Then you can use the mysqlbinlog command to see all data-modifying statements.

share|improve this answer

I don't think some people understand the question (or I don't). You don't want to log the queries against the DB; rather a log from an application is going into a DB. If it were a file you could tail the log. How do you tail a table so that when a new row is added it is output?

It shouldn't be to hard to write a simple loop to handle this, assuming you have a unique field that monotonically increases over time (e.g., a sequence number).

current_pos = select max(seq) from table
while true
  new_pos = select max(seq) from table
  if new_pos > current_pos
    select * from table where seq > current_pos
    current_pos = new_pos
  sleep 1
share|improve this answer

It appears that many of us don't quite understand your question. What do you mean by "logging database", which isn't a standard MySQL term.

Use the MySQL General Query Log, which logs each statement received from a client.

You can then set log_output = TABLE in your my.cnf . The file will be written to $mysql_data_directory/general_log.CSV . You can tail -f this file to view queries in real time.

share|improve this answer

You could do it a hacky way by using tail -f on the database file (/var/lib/mysql/database_name/table_name.MY*) and then running your query every time a line is read.

share|improve this answer

I suggest adding a timestamp field to any table you want to tail. That will allow you to get the desired results very easily with a simple query.

share|improve this answer

You might like to give this a go:

It's old and hasn't been touched for 3 years - but I just tried it out and it works OK. Clone the BZR repo and read the README.

share|improve this answer

Here's what I use. Seems the simplest solution, though it's not very efficient:

watch "mysql db_name -e '(SELECT * FROM my_table ORDER BY id DESC LIMIT 10) ORDER BY id ASC;'"

share|improve this answer

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.