Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching MySQL Bin Log for a Query

Is it possible to query the mysql bin log for a particular query? For example, suppose I want to know if anyone in the last hour did a specific query (like 'Update tableX where userName = 'bob'"). I just want to see if a particular query has been run recently.....

like image 539
David Avatar asked Oct 08 '10 12:10

David


2 Answers

Use mysqlbinlog - nix or mysqlbinlog.exe - windows

$bash>mysqlbinlog mysql_bin.log > mysql_bin.txt

After conversion You can search DML in mysql_bin.txt

like image 158
baklarz2048 Avatar answered Oct 12 '22 10:10

baklarz2048


mysqlbinlog ${1} |grep -i  'update\|insert\|delete\|replace\|alter' | tr ‘[A-Z]’ ‘[a-z]’|sed -e '/*/d' | sort | uniq -c | sort -nr
like image 36
Jeeva Avatar answered Oct 12 '22 08:10

Jeeva