Scenario: Sometimes the binary files in the disk are deleted due to disk corruption or human error, resulting in a mismatch between the show binary logs record in MySQL and the binary file in the actual physical disk
#binlogdiff. Sh
#!/bin/sh
#[email protected]
#作用: MySQL show binary logs recorded binary log file and actual physical file comparison, 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 log file for binary logs records
Binlog_res=tmpres. ' Date +%y%m%d%h%m%s '. txt #binlog物理磁盘路径中的日志文件
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}