Problem Scenario: Sometimes the binary files on the disk are deleted because of disk corruption or human error, causing the show binary logs record in MySQL to not match the binaries in the actual physical disk
#binlogdiff. SH #!/bin/sh #ocpyang @126.com #作用: Show binary logs records binary log files and actual physical file comparisons in MySQL, check #磁盘中对应的二进制日志文件是否有丢失 Source/usr/local/mysql/scripts/mysql_env.ini binlog_init=tmpinit. ' Date +%y%m%d%h%m%s '. txt Binlog_midd=tmpmidd . ' Date +%y%m%d%h%m%s '. txt #mysql中show binary logs log file binlog_res=tmpres. ' Date +%y%m%d%h%m%s ' txt # Binlog log files in a physical disk path my_cnf=/usr/local/mysql/my.cnf #mysql的配置文件 log_bin_path= ' grep-i ^log-bin ' $my _cnf |cut-d =-F 2 ' log_bin= ' dirname $log _bin_path ' #lookup binlog records in MySQL mysql-h${mysql_host}-u${mysql_user} -p${mysql_pass}-e "show binary logs;" >${binlog_init} Cat ${binlog_init} | Cut-f 1 |cut-d. -F 2 |grep-i ' ^[0-9] ' |sort-n >${binlog_midd} #lookup binlog records in Disk Ls-t ${log_bin}| grep ' ^mysql-bin ' |cut-d.
-F 2 |grep-i ' ^[0-9] ' |sort-n >${binlog_res} diff-c ${binlog_midd} $binlog _res #clean temp file RM-RF ${binlog_init} rm-rf ${binlog_midd} RM-RF ${binlog_res}
This column more highlights: http://www.bianceng.cn/database/MySQL/