一般如果直接cat 或tail 會出現亂碼
[root@rosalie-mysql01 mysql]# cat mysql-bin.000015 |more
þbinSf¹\
--More--
test_table24iem8rUUx0aVBOYz0iLCJtYWMiOiIyM2Y3ODQwNzEzZGYwMjU5OTkwMTlmOGJiYjBlNjdkZmE1NWQ3YzVjYmZjYjk2ODliMWJhYmZkMTI0ZTkzODE5In0=GN6TmpVek5qTTBNMkUxTkE9PSIsInZhbHVlIjoiUUJQZmJocVwvMTB5VEl6YkVIcm9HcWVGb1wvM25IQnJiRmxnUGdFd1BQUUw1RmNqczVOZkhhV1RSR0F0eGpldnROIiwibWFj
IjoiN2FiODdmYWU1ZWQ1NmIxY2VjOTUwYjA4NmNkYjYyNTY5NmYzYzg4ZDI2YTY5NmQzN2YzNjRkMTM3YzViNjNkZSJ9
TmpVek5qTTBNMkUxTkE9PSIsInZhbHVlIjoiWjA1cjB3YVE4eXpndGdyODJhTjgxUzJqR01tcUZ4T1J3TWxMRytRZ1hsQT0iLCJtYWMiOiI1NDNhNTY3ODEzZjVmYzNiMzRiNTZ
方式一
:
先導出成txt檔,然後即可直接查看
mysqlbinlog mysql-bin.000015 > /tmp/binlog-dump.txt
方式二:選取要查詢的某時段(如果不確定是哪一個檔案用*)
mysqlbinlog --start-datetime="2006-01-01 00:00:00" --stop-datetime="2019-05-08 00:00:00" /var/lib/mysql/mysql-bin.* > /tmp/mysql_restore.txt
方式三:直接查看不再導出
mysqlbinlog mysql-bin.000015 -vv |more
案例一:如果需要復原到某一個時間點(例如刪除了某筆資料,還原到刪除前 ),針對單一DB
查到刪除前位置是808,所以要復原
rookery這個DB,需先把BINLOG單一匯出,再將SQL導入到刪除前
,因為BINLOG是記錄所有DB,若不單一導出,這樣會連同其他的DB也一起導出 ,再匯入時就會造成資料重覆
mysqlbinlog –stop-position=808 /usr/local/mysql/data/mysql-bin.000015 --database=rookery > /tmp/4abc3.txt
案例二:取開啟到結束的時間 ,指定DB
mysqlbinlog --start-datetime="2018-11-02 12:00:00" --stop-datetime="2018-11-02 12:10:00" --database=goods /usr/local/mysql/data/mysql-bin.000015 > /tmp/aaa.txt
案例三:查到DROP字段往後取200行
mysqlbinlog -vv mysql-bin.000015 | grep -A 200 "drop"
沒有留言:
張貼留言