======================================================================
MySQL Binlog常用參數
log_bin 設置此參數表示啟用binlog功能,並指定路徑名稱 log_bin_index 設置此參數是指定二進制索引文件的路徑與名稱 binlog_do_db 此參數表示只記錄指定數據庫的二進制日志 binlog_ignore_db 此參數表示不記錄指定的數據庫的二進制日志 max_binlog_cache_size 此參數表示binlog使用的內存最大的尺寸 binlog_cache_size 此參數表示binlog使用的內存大小,可以通過狀態變量binlog_cache_use和binlog_cache_disk_use來幫助測試。 binlog_cache_use:使用二進制日志緩存的事務數量 binlog_cache_disk_use:使用二進制日志緩存但超過binlog_cache_size值並使用臨時文件來保存事務中的語句的事務數量 max_binlog_size Binlog最大值,最大和默認值是1GB,該設置並不能嚴格控制Binlog的大小,尤其是Binlog比較靠近最大值而又遇到一個比較大事務時,為了保證事務的完整性,不可能做切換日志的動作,只能將該事務的所有SQL都記錄進當前日志,直到事務結束 sync_binlog 該參數直接影響mysql的性能和完整性 sync_binlog=0: 當事務提交后,Mysql僅僅是將binlog_cache中的數據寫入Binlog文件,但不執行fsync之類的磁盤 同步指令通知文件系統將緩存刷新到磁盤,而讓Filesystem自行決定什么時候來做同步,這個是性能最好的。 sync_binlog=n,在進行n次事務提交以后,Mysql將執行一次fsync之類的磁盤同步指令,同志文件系統將Binlog文件緩存刷新到磁盤。 Mysql中默認的設置是sync_binlog=0,即不作任何強制性的磁盤刷新指令,這時性能是最好的,但風險也是最大的。一旦系統綳Crash,在文件系統緩存中的所有Binlog信息都會丟失
======================================================================
會話級別log_bin參數
在MySQL配置文件中使用log_bin=1來設置MySQL生成binlog文件。 而如果希望當前回話執行的命令不寫入binlog文件,可以使用SQL_LOG_BIN參數來設置。 SET SESSION SQL_LOG_BIN=0 如果設置GLOBAL級別SQL_LOG_BIN,會影響所有回話寫binlog日志,謹慎使用!
======================================================================
binlog_rows_query_log_events參數
默認配置下,ROW格式二進制日志只記錄數據發生的變化,並不會記錄什么語句導致數據發生變化,而出於審計或者處理bug的需求,需要了解導致數據變化的SQL語句,MYSQL提供了binlog_rows_query_log_events來控制是否在二進制中存放"原始SQL"。
binlog_rows_query_log_events參數默認不啟用。
The binlog_rows_query_log_events system variable affects row-based logging only. When enabled, it causes the MySQL Server to write informational log events such as row query log events into its binary log. This information can be used for debugging and related purposes; such as obtaining the original query issued on the master when it cannot be reconstructed from the row updates.
These events are normally ignored by MySQL programs reading the binary log and so cause no issues when replicating or restoring from backup.
當binlog_rows_query_log_events開啟后,通過解析出Binlog結構可以找到都導致數據發生變化的SQL語句。