日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql binlog redo_mysql的binlog与redo log

發(fā)布時(shí)間:2023/12/1 数据库 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql binlog redo_mysql的binlog与redo log 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

binlog

Mysql Binlog是二進(jìn)制格式的日志文件,用來記錄Mysql內(nèi)部對數(shù)據(jù)庫的改動(只記錄對數(shù)據(jù)的修改操作),主要用于數(shù)據(jù)庫的主從復(fù)制以及增量恢復(fù)。

獲取binlog日志列表

MariaDB [examples]> show master logs;

+-----------+-----------+

| Log_name | File_size |

+-----------+-----------+

| ON.000001 | 9893 |

+-----------+-----------+

可知當(dāng)前只有一個(gè)binlog文件:ON.000001

MariaDB [examples]> show binary logs;

+-----------+-----------+

| Log_name | File_size |

+-----------+-----------+

| ON.000001 | 9893 |

+-----------+-----------+

1 row in set (0.134 sec)

查看examples.prefix的表結(jié)構(gòu)

MariaDB [examples]> show create table prefix \G;

*************************** 1. row ***************************

Table: prefix

Create Table: CREATE TABLE `prefix` (

`a` int(10) NOT NULL,

`b` int(10) NOT NULL,

`c` int(10) NOT NULL,

KEY `I_index` (`a`,`b`,`c`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

對全表進(jìn)行更新操作

MariaDB [examples]> update prefix set b=a+101;

Query OK, 32 rows affected (0.201 sec)

Rows matched: 32 Changed: 32 Warnings: 0

可以看到有32條數(shù)據(jù)發(fā)生了更新

查看binlog(也可以在日志文件目錄通過mysqlbinlog ON.000001命令查看)

MariaDB [(none)]> show binlog events in 'ON.000001' \G;

...

...

...

*************************** 108. row ***************************

Log_name: ON.000001

Pos: 9893

Event_type: Gtid

Server_id: 1

End_log_pos: 9935

Info: BEGIN GTID 0-1-48

*************************** 109. row ***************************

Log_name: ON.000001

Pos: 9935

Event_type: Query

Server_id: 1

End_log_pos: 10031

Info: use `examples`; update prefix set b=a+101

*************************** 110. row ***************************

Log_name: ON.000001

Pos: 10031

Event_type: Xid

Server_id: 1

End_log_pos: 10062

Info: COMMIT /* xid=883 */

有很多條記錄,本次更新操作增加了這三條數(shù)據(jù),其中第109是我們顯示執(zhí)行的SQL,而第108與109條是事務(wù)的開始與結(jié)束。

關(guān)于Xid:

Binlog::GTID_EVENT:

A global transaction identifier (GTID)

開啟事務(wù)

Binlog::QUERY_EVENT:

The query event is used to send text querys right the binlog.

mysql中create,insert,update,delete的Event_type均為Query類型,初看覺得很奇怪,這里只是類型定義而已。

Binlog::XID_EVENT:

Transaction ID for 2PC, written whenever a COMMIT is expected.

提交事務(wù)

看看官方對各個(gè)字段的解釋

Log_name

The name of the file that is being listed.

Pos

The position at which the event occurs.

Event_type

An identifier that describes the event type.

Server_id

The server ID of the server on which the event originated.

End_log_pos

The position at which the next event begins, which is equal to Pos plus the size of the event.

Info

More detailed information about the event type. The format of this information depends on the event type.

redo log

The redo log is a disk-based data structure used during crash recovery to correct data written by incomplete transactions

關(guān)于redo log,文件名前綴為ib_logfile, 嘗試用mysqlbinlog讀取

mysqlbinlog ib_logfile1

/*!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 /*!*/;

ERROR: File is not a binary log file.

google一圈,目前尚沒發(fā)現(xiàn)有可以解析該類文件的工具,只能從文檔中了解其具體結(jié)構(gòu)。

后面有時(shí)間研究下源碼,寫個(gè)ib_logfile的解析器玩玩

參考:

總結(jié)

以上是生活随笔為你收集整理的mysql binlog redo_mysql的binlog与redo log的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。