mysqlbinlog工具的作用是什么呢,如何將binary log轉換為文本格式?


需求描述:

  今天在看mysqlbinlog這個工具,就在想這個工具到底是干嘛的呢,在mysql數據庫中,

  binary log中記錄了數據庫內容的變化或者說修改,這些修改是以二進制的方式存儲到

  binary log中的,那么要想將二進制格式轉換成為文本格式,即通過文本格式顯示

操作過程:

1.直接通過mysqlbinlog工具,將binary log以文本格式顯示

mysqlbinlog mysql-bin.000031 > /tmp/mysql-bin.000031.txt

備注:將mysql-bin日志進行解析,並且將輸出存放在txt文件中

2.查看生成的txt文件

[mysql@redhat6 data]$ more /tmp/mysql-bin.000031.txt
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#180411  9:32:38 server id 1  end_log_pos 107     Start: binlog v 4, server v 5.5.57-log created 180411  9:32:38 at startup
ROLLBACK/*!*/;
BINLOG '
tmXNWg8BAAAAZwAAAGsAAAAAAAQANS41LjU3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAC2Zc1aEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#180411  9:48:56 server id 1  end_log_pos 220     Query    thread_id=11    exec_time=0    error_code=0
use `employees`/*!*/;
SET TIMESTAMP=1523411336/*!*/;
SET @@session.pseudo_thread_id=11/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
DROP TABLE `titles` /* generated by server */
/*!*/;
# at 220
#180411  9:49:01 server id 1  end_log_pos 335     Query    thread_id=11    exec_time=0    error_code=0
SET TIMESTAMP=1523411341/*!*/;
DROP TABLE `salaries` /* generated by server */
/*!*/;
# at 335
#180411  9:49:20 server id 1  end_log_pos 408     Query    thread_id=12    exec_time=0    error_code=0
SET TIMESTAMP=1523411360/*!*/;
BEGIN
/*!*/;
# at 408
#180411  9:49:20 server id 1  end_log_pos 524     Query    thread_id=12    exec_time=0    error_code=0
SET TIMESTAMP=1523411360/*!*/;

備注:其中就記錄了時間,binlog的位置.做了操作的SQL語句.

 

文檔創建時間:2018年4月18日11:13:57


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM