mysqlbinlog -》 解析 mysql的binlog日志
mysql 的binlog日志是什么
数据目录下的如下文件就是mysql的binlog日志
'''
[root@mangodb mysql]# ls
bin.sql mangodb.pid mysqlbin_scott.000004 mysqlbin_scott.index
ibdata1 mysql mysqlbin_scott.000005 Scot
ib_logfile0 mysqlbin_scott.000001 mysqlbin_scott.000006 performance_schema
ib_logfile1 mysqlbin_scott.000002 mysqlbin_scott.000007 scott
mangodb.err mysqlbin_scott.000003 mysqlbin_scott.000008 test2
[root@mangodb mysql]# cat mysqlbin_scott.index
./mysqlbin_scott.000001
./mysqlbin_scott.000002
./mysqlbin_scott.000003
./mysqlbin_scott.000004
./mysqlbin_scott.000005
./mysqlbin_scott.000006
./mysqlbin_scott.000007
./mysqlbin_scott.000008
'''
日志作用是什么?
用来记录mysql内部增删改等 对mysql数据库有更新的内容记录
[root@mangodb mysql]# mysqlbinlog mysqlbin_scott.000008 |egrep -v "#|\*|--|^$"
备份的时候 -d dbname 指定数据库名字 就可以了
binlog 文件里面是记录所有库的数据 想要备份一个数据库 命令如下
[root@mangodb mysql]# mysqlbinlog -d scott mysqlbin_scott.000008 > scott.sql
位置点恢复
[root@mangodb mysql]# mysqlbinlog mysqlbin_scott.000008 --start-position=8859 --stop-position=8959 -r pos.sql
指定时间 时间不准确 因为1秒钟有可能有很多语句
[root@mangodb mysql]# mysqlbinlog mysqlbin_scott.000008 --start-datetime='2016-10-16 17:14:15' --stop-datetime='2016-10-16 17:17:15' -r pos.sql