mysql binlog redo_mysql的binlog与redo log
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做完人流多少钱啊?
- 下一篇: mysql5 varchar_MYSQL