国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql關于ib_logfile事務日志和binary log二進制日志的區別

2024-07-24 12:34:41
字體:
來源:轉載
供稿:網友
  總結
 
  1、ib_logfile類似oracle的online redo log,包含commit和uncommit的數據
 
  2、binary log類似oracle的online redo log和archive redo log,但是只有commit的數據
 
  statement 格式的 binlog,最后會有 COMMIT;
  row 格式的 binlog,最后會有一個 XID event
 
  3、為什么MySQL有binlog,還要redo log?因為MySQL是多存儲引擎的,不管使用那種存儲引擎,都會有binlog,而不一定有redo log。而redo log 事務日志ib_logfile文件是InnoDB存儲引擎產生的
 
  4、ib_logfile是循環使用,binary log不是循環使用,在寫滿或者重啟之后,會生成新的binary log文件
 
  5、兩種日志記錄的內容差不多類似,都是事務對應DML、DDL的信息,只是作用不同,內容可能重復,比如一個DML記錄在了ib_logfile也記錄在了binary log
 
  6、ib_logfile作為異常宕機后啟動時恢復使用
 
  7、binary log作為數據恢復使用,主從復制搭建使用
 
  8、兩種日志寫入磁盤的觸發點不同,二進制日志只在事務提交完成后進行一次寫入,重做日志在事務提交會寫入每隔1秒也會寫入。MySQL為了保證master和slave的數據一致性,就必須保證binlog和InnoDB redo日志的一致性(因為備庫通過二進制日志重放主庫提交的事務,如果主庫commit之前就寫入binlog,一旦主庫crash,再次啟動時會回滾事務。但此時從庫已經執行,則會造成主備數據不一致)。所以必須保證二進制日志只在事務提交完成后進行一次寫入
 
  9、在主從復制結構中,要保證事務的持久性和一致性,對兩種日志的相關變量設置為如下最為妥當:sync_binlog=1(即每提交一次事務同步寫到磁盤中);innodb_flush_log_at_trx_commit=1(即每提交一次事務都寫到磁盤中)。這兩項變量的設置保證了:每次提交事務都寫入二進制日志和事務日志,并在提交時將它們刷新到磁盤中
 
  10、innodb中,表數據刷盤的規則只有一個:checkpoint。但是觸發checkpoint的情況卻有幾種(1.重用redo log文件;2.臟頁達到一定比例)
 
  11、ib_logfile作為redo log記錄的是“做了什么改動”,是物理日志,記錄的是"在某個數據頁上做了什么修改";
 
         binary log記錄的是這個語句的原始邏輯,分兩種模式,statement格式記錄的是sql語句,row格式記錄的是行的內容,記錄更新前和更新后的兩條數據。
 
  使用下面的方法查看ib_logfile里的內容
 
  [root@mydb ~]# strings /var/lib/mysql/ib_logfile0
 
  使用下面兩種方法查看binary log的內容
 
  mysqlbinlog mysql-bin.000002
 
  mysql> show binlog events in 'mysql-bin.000002';
 
  mysql> show binlog events in 'mysql-bin.00002' from 504769752 limit 30,30;
  mysql> show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
  選項解析:
  IN 'log_name'   指定要查詢的binlog文件名(不指定就是第一個binlog文件)
  FROM pos        指定從哪個pos起始點開始查起(不指定就是從整個文件首個pos點開始算)
  LIMIT [offset,] 偏移量(不指定就是0)
  row_count       查詢總條數(不指定就是所有行)
 
  ib_logfile
 
  A set of files, typically named ib_logfile0 and ib_logfile1, that form the redo log. Also sometimes referred to as the log group. These files record statements that attempt to change data in InnoDB tables. These statements are replayed automatically to correct data written by incomplete transactions, on startup following a crash.
 
  This data cannot be used for manual recovery; for that type of operation, use the binary log.
 
  一組文件,通常名為ib_logfile0和ib_logfile1,構成重做日志。 有時也稱為日志組。 這些文件記錄了嘗試更改InnoDB表中數據的語句。 在崩潰后啟動時,會自動重播這些語句以更正由不完整事務寫入的數據。
 
  此數據不能用于手動恢復; 對于該類型的操作,請使用二進制日志。
 
  binary log
 
  The binary log contains “events” that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE which matched no rows), unless row-based logging is used. The binary log also contains information about how long each statement took that updated data. The binary log has two important purposes:
 
  For replication
 
  Certain data recovery operations require use of the binary log.After a backup has been restored, the events in the binary log that were recorded after the backup was made are re-executed. These events bring databases up to date from the point of the backup.
 
  二進制日志包含描述數據庫更改的“事件”,例如表創建操作或對表數據的更改。 它還包含可能已進行更改的語句的事件(例如,不匹配任何行的DELETE),除非使用基于行的日志記錄。 二進制日志還包含有關每個語句獲取更新數據的時間長度的信息。
 
  二進制日志有兩個重要目的:
 
  用于復制
 
  某些數據恢復操作需要使用二進制日志。備份恢復后,將重新執行備份后記錄的二進制日志中的事件。 這些事件使數據庫從備份點更新。
 
  The binary log is not used for statements such as SELECT or SHOW that do not modify data.
 
  二進制日志不用于不修改數據的SELECT或SHOW等語句
 
  checkpoint
 
  As changes are made to data pages that are cached in the buffer pool, those changes are written to the data files sometime later, a process known as flushing. The checkpoint is a record of the latest changes (represented by an LSN value) that have been successfully written to the data files.
 
  當對緩沖池中緩存的數據頁進行更改時,這些更改將在稍后的某個時間寫入數據文件,這一過程稱為刷新。 檢查點是已成功寫入數據文件的最新更改(由LSN值表示)的記錄。
 
  sharp checkpoint
 
  The process of flushing to disk all dirty buffer pool pages whose redo entries are contained in certain portion of the redo log. Occurs before InnoDB reuses a portion of a log file ; the log files are used in a circular fashion. Typically occurs with write-intensive workloads.
 
  將重做條目包含在重做日志的某些部分中的所有臟緩沖池頁面刷新到磁盤的過程。 在InnoDB覆蓋重用日志文件之前發生 ; 日志文件以循環方式使用。 通常發生寫入密集型工作負載。
 
  flush
 
  To write changes to the database files , that had been buffered in a memory area or a temporary disk storage area. The InnoDB storage structures that are periodically flushed include the redo log, the undo log, and the buffer pool.
 
  Flushing can happen because a memory area becomes full and the system needs to free some space , because a commit operation means the changes from a transaction can be finalized, or because a slow shutdown operation means that all outstanding work should be finalized. When it is not critical to flush all the buffered data at once, InnoDB can use a technique called fuzzy checkpointing to flush small batches of pages to spread out the I/O overhead.
 
  將發生在內存區域或臨時磁盤存儲區域中緩沖的 更改寫入數據庫文件 。 定期刷新的InnoDB存儲結構包括重做日志,撤消日志和緩沖池。
 
  刷新可能是因為 內存區域已滿并且系統需要釋放一些空間 ,因為提交操作意味著可以最終確定事務的更改,或者因為慢速關閉操作意味著應該最終完成所有未完成的工作。 當一次刷新所有緩沖數據并不重要時,InnoDB可以使用一種稱為 模糊檢查點 的技術來刷新小批量頁面以分散I / O開銷。

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉门市| 达尔| 滦南县| 石棉县| 西充县| 盐城市| 灌南县| 兰州市| 伊宁县| 固始县| 会泽县| 高台县| 桦川县| 扬中市| 金湖县| 北辰区| 同仁县| 肃宁县| 苏尼特左旗| 江永县| 清原| 绵阳市| 桓台县| 库尔勒市| 镇江市| 南京市| 双鸭山市| 莱芜市| 福清市| 边坝县| 达尔| 丰原市| 康定县| 巴东县| 铅山县| 吐鲁番市| 扬州市| 鱼台县| 南木林县| 珲春市| 辉县市|