1

I am trying to find out when some queries have been executed on our DB. For that I started looking in MySql binarylogs, using mysqlbinlog:

find -name "binlog.000056*" -exec mysqlbinlog {} \; | grep -i "update .* my_special_column=value"

The problem is that this way I cannot find out in which file it finds results, as grep gets the input from its input (through pipe) and not from a direct file.

I thought using tee, but did not succeed.

So the question: how to use find -exec mysqlbinlog... and grep, showing also the filename where grep finds the result?

V G
  • 145

2 Answers2

1

There are comments and timestamps that appear above each SQL command.

When you run the grep, use the -A, -B, or -C option.

What that does is the following

  • -A shows you a number of lines after the pattern is found
  • -B shows you a number of lines before the pattern is found
  • -C shows you a number of lines before and after the pattern is found

For example, run the grep like this to include 2 lines above the matching pattern

find -name "binlog.000056*" -exec mysqlbinlog {} \; | grep -i -B 2 "update .* my_special_column=value"

If you want the iterate through the names and see the filename, do this

for X in `ls binlog.000056*` ; do echo ${X} ; mysqlbinlog ${X} | grep -i -B 2 "update .* my_special_column=value" ; done

Give it a Try !!!

0

You need to run multiple commands in exec. Have a look to this question and the different answers.

Zimmi
  • 351