mysqlbinlog命令介紹

2021-08-02 20:26:52 字數 1778 閱讀 5297

1、mysqlbinlog

1.1、 mysqlbinlog作用: 解析mysqlbinlog日誌

1.2、mysqlbinlog日誌是什麼?

在mysql資料庫中的資料目錄的下述檔案:

mysql-bin.000001

mysql-bin.000002

mysql-bin.000003

mysql-bin.index

1.3、mysql的binlog日誌作用:

mysql內部對mysql資料庫有增刪改等更新的內容的記錄

1.4、檢視mysqlbinlog的安裝位置:

which binlog

1.5、binlog功能怎麼開啟:

grep log-bin /etc/my.cnf

2、備份:

2.1、備份000003時整個資料庫的狀態資訊:

mysqlbinlog mysqlbinlog日誌 >備份檔案名 

#mysqlbinlog mysql-bin.000003 >all.sql

2.2、拆庫只備份000003時zdh資料庫的狀態資訊:

mysqlbinlog -d 資料庫名 mysqlbinlog日誌 >備份檔案名

#mysqlbinlog -d zdh mysql-bin.000003 >zdh.sql

2.3、指定開始和結束位置點和時間點備份:

2.3.1、指定開始和結束位置點備份:

mysqlbinlog mysqlbinlog日誌 --start-position=開始點--stop-position=結束點 >備份檔案名 

less all.sql(可以看到

#at 365

#141016 17:13:05 server id 1 end_log_pos 456

insert into test values(5)

#at 456

#141016 17:13:06 erver id 1 end_log_pos 483

) #mysqlbinlog mysql-bin.000003 --start-position=365 --stop-position=456 >r.sql

2.3.2、指定開始和結束時間點備份:(不推薦,不準確)

mysqlbinlog mysqlbinlog日誌 --start-datatime=開始時間--stop-datatime=結束時間 >備份檔案名 

less all.sql(可以看到

#at 365

#141016 17:13:05 server id 1 end_log_pos 456

insert into test values(5)

#at 456

#141016 17:13:06 erver id 1 end_log_pos 483

) #mysqlbinlog mysql-bin.000003 --start-datatime='2017-06-21 17:13:05'--stop-datatime='2017-06-21 17:13:06' >r1.sql

3、總結:

-d 擷取指定資料庫的binlog

按照位置擷取:#mysqlbinlog mysql-bin.000003 --start-position=365 --stop-position=456 >r.sql

按照時間擷取:#mysqlbinlog mysql-bin.000003 --start-datatime='2017-06-21 17:13:05'--stop-datatime='2017-06-21 17:13:06'            >r1.sql

mysqlbinlog簡單介紹

binlog二進位制日誌包含描述資料庫更改的 事件 如表建立操作或表資料更改。除非使用基於行的日誌記錄,否則它還包含可能已進行更改的語句的事件 例如,不匹配任何行的delete 二進位制日誌還包含關於每個語句花費多長時間更新資料的資訊。二進位制日誌有兩個重要的用途 1 備份,用於從伺服器的備份。主伺...

mysqlbinlog命令使用

常用引數 start datetime datetime 從二進位制日誌中第1個日期時間等於或晚於datetime參量的事件開始讀取。datetime值相對於執行mysqlbinlog的機器上的本地時區。該值格式應符合datetime或timestamp資料型別。stop datetime date...

mysql binlog備份初探

備份mysql的binlog檔案,可以配合分庫或全庫的備份檔案實現基於時間點的資料恢復.在工作過程中,遇到兩種情況 1.不執行flush logs命令 缺點 對於不進行頻繁寫入和更新的業務,備份後,浪費磁碟空間.優點 對於一天只生成乙個binlog檔案的業務,恢復資料比較容易,只需要解壓乙個binl...