DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Analyse Binary Log

10.22.2011
| 2667 views |
  • submit to reddit
        // A shell script to analyse statements from binary log.

# cat /bin/mylog
#!/bin/sh
# usage:
#$ mylog /mysql-bin-log/db-bin.000223
#   2132 insert into customers
#   1887 update userlog_access
#    788 insert into gn_commission
#    718 insert into con_tab 

mysqlbinlog ${1} | grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | sort | uniq -c | sort -nr