Skip to content

Instantly share code, notes, and snippets.

@kevinclcn
Forked from Capncavedan/gist:2844679
Last active August 15, 2018 07:39
Show Gist options
  • Save kevinclcn/1df8bf7116acc9fda96576c79531527f to your computer and use it in GitHub Desktop.
Save kevinclcn/1df8bf7116acc9fda96576c79531527f to your computer and use it in GitHub Desktop.
Analyze MySQL binary log file
# from http://dzone.com/snippets/analyse-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 -v ${1} \
| grep -i -e "^### update" -e "^### insert" -e "^### delete" -e "^### replace" -e "^### alter" \
| cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/### //g;s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" \
| sed -e "s/ where .*$//" \
| sort \
| uniq -c \
| sort -nr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment