溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MYSQL中Binglog分析利器binlog2sql怎么用

發(fā)布時(shí)間:2021-11-06 11:22:07 來源:億速云 閱讀:127 作者:小新 欄目:MySQL數(shù)據(jù)庫(kù)

這篇文章將為大家詳細(xì)講解有關(guān)MYSQL中Binglog分析利器binlog2sql怎么用,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

一、binlog2sql簡(jiǎn)介
binlog2sql是一開源工具,其可以從MySQL binlog解析出你要的SQL。根據(jù)不同選項(xiàng),你可以得到原始SQL、回滾SQL、去除主鍵的INSERT SQL等。
主要用途如下:
(1)數(shù)據(jù)快速回滾(閃回)
(2)主從切換后數(shù)據(jù)不一致的修復(fù)
(3)從binlog生成標(biāo)準(zhǔn)SQL,帶來的衍生功能
二、binlog2sql安裝
1、binlog2sql下載
https://github.com/danfengcao/binlog2sql
2、binlog2sql依賴包安裝
python2.6+
PyMySQL==0.7.8+
wheel==0.24.0+
mysql-replication==0.9+
(1)PyMySQL-0.7.10安裝
https://pypi.python.org/pypi/PyMySQL/
[root@node1 binlogsql]# tar -xzvf PyMySQL-0.7.10.tar.gz
[root@node1 binlogsql]# cd PyMySQL-0.7.10
[root@node1 PyMySQL-0.7.10]# python setup.py install
(2)wheel-0.30.0a0安裝
https://pypi.python.org/pypi/wheel/
[root@node1 binlogsql]# tar -xzvf wheel-0.30.0a0.tar.gz
[root@node1 binlogsql]# cd wheel-0.30.0a0
[root@node1 wheel-0.30.0a0]# python setup.py install
(3)python-mysql-replication安裝
https://github.com/noplay/python-mysql-replication
[root@node1 binlogsql]# unzip python-mysql-replication-master.zip
[root@node1 binlogsql]# cd python-mysql-replication-master
[root@node1 python-mysql-replication-master]# python setup.py  install
(4)可以通過pip安裝相應(yīng)的依賴包
https://pypi.python.org/pypi/pip
[root@node1 tools]# tar -xzvf pip-9.0.1.tar.gz
[root@node1 tools]# cd pip-9.0.1
[root@node1 pip-9.0.1]# python setup.py install
[root@node1 binlog2sql-master]# pip install  -r requirements.txt
3、binlog2sql安裝
直接下載解壓縮即可,運(yùn)行相應(yīng)的py腳本

[root@node1 tools]# unzip binlog2sql-master.zip
[root@node1 tools]# cd binlog2sql-master
設(shè)置別名,方便命令調(diào)用:
alias binlog2sql='python /tools/binlogsql/binlog2sql-master/binlog2sql/binlog2sql.py'
三、binlog2sql使用
1、binlog2sql幫助手冊(cè)
[root@node1 binlog2sql]# binlog2sql  --help
usage: binlog2sql.py [-h HOST] [-u USER] [-p PASSWORD] [-P PORT]
                     [--start-file STARTFILE] [--start-position STARTPOS]
                     [--stop-file ENDFILE] [--stop-position ENDPOS]
                     [--start-datetime STARTTIME] [--stop-datetime STOPTIME]
                     [--stop-never] [--help] [-d [DATABASES [DATABASES ...]]]
                     [-t [TABLES [TABLES ...]]] [-K] [-B]

Parse MySQL binlog to SQL you want

optional arguments:
  --stop-never          Wait for more data from the server. default: stop
                        replicate at the last binlog when you start binlog2sql  ##持續(xù)同步binlog??蛇x。不加則同步至執(zhí)行命令時(shí)最新的binlog位置
  --help                help infomation
  -K, --no-primary-key  Generate insert sql without primary key if exists ##對(duì)INSERT語句去除主鍵??蛇x。
  -B, --flashback       Flashback data to start_postition of start_file ##生成回滾語句,可解析大文件,不受內(nèi)存限制,每打印一千行加一句SLEEP SELECT(1)??蛇x。與stop-never或no-primary-key不能同時(shí)添加。

connect setting:
  -h HOST, --host HOST  Host the MySQL database server located
  -u USER, --user USER  MySQL Username to log in as
  -p PASSWORD, --password PASSWORD
                        MySQL Password to use
  -P PORT, --port PORT  MySQL port to use

range filter:
  --start-file STARTFILE
                        Start binlog file to be parsed  ##起始解析文件。必須。
  --start-position STARTPOS, --start-pos STARTPOS ##start-file的起始解析位置??蛇x。默認(rèn)為start-file的起始位置。
                        Start position of the --start-file
  --stop-file ENDFILE, --end-file ENDFILE            ##末尾解析文件??蛇x。默認(rèn)為start-file同一個(gè)文件。若解析模式為stop-never,此選項(xiàng)失效。
                        Stop binlog file to be parsed. default: '--start-file'
  --stop-position ENDPOS, --end-pos ENDPOS    ##stop-file的末尾解析位置??蛇x。默認(rèn)為stop-file的最末位置;若解析模式為stop-never,此選項(xiàng)失效。
                        Stop position of --stop-file. default: latest position
                        of '--stop-file'
  --start-datetime STARTTIME
                        Start reading the binlog at first event having a
                        datetime equal or posterior to the argument; the
                        argument must be a date and time in the local time
                        zone, in any format accepted by the MySQL server for
                        DATETIME and TIMESTAMP types, for example: 2004-12-25
                        11:25:56 (you should probably use quotes for your
                        shell to set it properly). ##從哪個(gè)時(shí)間點(diǎn)的binlog開始解析,格式必須為datetime,如'2016-11-11 11:11:11'??蛇x。默認(rèn)不過濾。
  --stop-datetime STOPTIME
                        Stop reading the binlog at first event having a
                        datetime equal or posterior to the argument; the
                        argument must be a date and time in the local time
                        zone, in any format accepted by the MySQL server for
                        DATETIME and TIMESTAMP types, for example: 2004-12-25
                        11:25:56 (you should probably use quotes for your
                        shell to set it properly).  ##到哪個(gè)時(shí)間點(diǎn)的binlog停止解析,格式必須為datetime,如'2016-11-11 11:11:11'??蛇x。默認(rèn)不過濾。

schema filter:
  -d [DATABASES [DATABASES ...]], --databases [DATABASES [DATABASES ...]]
                        dbs you want to process  ##只輸出目標(biāo)db的sql??蛇x。默認(rèn)為空。
  -t [TABLES [TABLES ...]], --tables [TABLES [TABLES ...]]
                        tables you want to process  ##只輸出目標(biāo)tables的sql??蛇x。默認(rèn)為空。
2、binlog2sql要求mysql配置參數(shù)需包括以下內(nèi)容
[mysqld]
log-bin-index = /home/mysql/bin-index
max_binlog_size = 1G
binlog_format = row
binlog_row_image = full
log-bin = /home/mysql/mysql-bin
3、binlog2sql解析binlog案例
(1)解析某個(gè)binlog全部?jī)?nèi)容

點(diǎn)擊(此處)折疊或打開

  1. ##構(gòu)造binlog內(nèi)容

  2. (root:localhost:Wed Mar 15 11:45:32 2017)[(none)]>flush logs;

  3. Query OK, 0 rows affected (0.00 sec)


  4. (root:localhost:Wed Mar 15 11:45:36 2017)[(none)]>show master status \G

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

  6.              File: mysql-bin.000028

  7.          Position: 120

  8.      Binlog_Do_DB:

  9.  Binlog_Ignore_DB:

  10. Executed_Gtid_Set:

  11. 1 row in set (0.00 sec)

  12. (root:localhost:Wed Mar 15 11:45:40 2017)[(none)]>use dbtest;

  13. Database changed

  14. (root:localhost:Wed Mar 15 11:46:53 2017)[dbtest]>show tables;

  15. +------------------+

  16. | Tables_in_dbtest |

  17. +------------------+

  18. | T |

  19. | T1 |

  20. | t |

  21. | t1 |

  22. | t2 |

  23. +------------------+

  24. 5 rows in set (0.00 sec)


  25. (root:localhost:Wed Mar 15 11:46:54 2017)[dbtest]>drop table t1;

  26. Query OK, 0 rows affected (0.00 sec)


  27. (root:localhost:Wed Mar 15 11:46:57 2017)[dbtest]>drop table T;

  28. Query OK, 0 rows affected (0.01 sec)


  29. (root:localhost:Wed Mar 15 11:47:01 2017)[dbtest]>drop table T1;

  30. Query OK, 0 rows affected (0.01 sec)


  31. (root:localhost:Wed Mar 15 11:47:02 2017)[dbtest]>show tables;

  32. +------------------+

  33. | Tables_in_dbtest |

  34. +------------------+

  35. | t |

  36. | t2 |

  37. +------------------+

  38. 2 rows in set (0.00 sec)


  39. (root:localhost:Wed Mar 15 11:47:07 2017)[dbtest]>drop table t2;

  40. Query OK, 0 rows affected (0.00 sec)


  41. (root:localhost:Wed Mar 15 11:47:12 2017)[dbtest]>create table t1 select * from t;

  42. Query OK, 0 rows affected (0.02 sec)

  43. Records: 0  Duplicates: 0  Warnings: 0


  44. (root:localhost:Wed Mar 15 11:47:20 2017)[dbtest]>select * from t;

  45. Empty set (0.00 sec)


  46. (root:localhost:Wed Mar 15 11:47:23 2017)[dbtest]>desc t;

  47. +-------+---------+------+-----+---------+-------+

  48. | Field | Type | Null | Key | Default | Extra |

  49. +-------+---------+------+-----+---------+-------+

  50. | id | int(11) | YES | | NULL | |

  51. +-------+---------+------+-----+---------+-------+

  52. 1 row in set (0.00 sec)


  53. (root:localhost:Wed Mar 15 11:47:27 2017)[dbtest]>insert into t values(1),(2),(3);

  54. Query OK, 3 rows affected (0.01 sec)

  55. Records: 3  Duplicates: 0  Warnings: 0


  56. (root:localhost:Wed Mar 15 11:47:38 2017)[dbtest]>insert into t1 select * from t;

  57. Query OK, 3 rows affected (0.00 sec)

  58. Records: 3  Duplicates: 0  Warnings: 0


  59. (root:localhost:Wed Mar 15 11:47:45 2017)[dbtest]>update t1 set id='11' where id<10;

  60. Query OK, 3 rows affected (0.00 sec)

  61. Rows matched: 3  Changed: 3  Warnings: 0


  62. (root:localhost:Wed Mar 15 11:48:12 2017)[dbtest]>show master status \G

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

  64.              File: mysql-bin.000028

  65.          Position: 38968

  66.      Binlog_Do_DB:

  67.  Binlog_Ignore_DB:

  68. Executed_Gtid_Set:

  69. 1 row in set (0.00 sec)

正常語句是:python binlog2sql.py  -h20.1.0.10 -P3306 -udb_user -p'abc.123' -ddbtest  --start-file='mysql-bin.000028'
由于上文做了binlog2sql別名,這里可以通過別名直接調(diào)用命令:
[root@node1 binlog2sql]#  binlog2sql -h20.1.0.10 -P3306 -udb_user -p'abc.123' -ddbtest  --start-file='mysql-bin.000028'
USE dbtest;
DROP TABLE `t1` /* generated by server */;
USE dbtest;
DROP TABLE `T` /* generated by server */;
USE dbtest;
DROP TABLE `T1` /* generated by server */;
USE dbtest;
DROP TABLE `t2` /* generated by server */;
USE dbtest;
CREATE TABLE `t1` (
  `id` int(11) DEFAULT NULL
);
INSERT INTO `dbtest`.`t`(`id`) VALUES (1); #start 35104 end 35274 time 2017-03-15 11:47:38
INSERT INTO `dbtest`.`t`(`id`) VALUES (2); #start 35104 end 35274 time 2017-03-15 11:47:38
INSERT INTO `dbtest`.`t`(`id`) VALUES (3); #start 35104 end 35274 time 2017-03-15 11:47:38
INSERT INTO `dbtest`.`t1`(`id`) VALUES (1); #start 36062 end 36233 time 2017-03-15 11:47:45
INSERT INTO `dbtest`.`t1`(`id`) VALUES (2); #start 36062 end 36233 time 2017-03-15 11:47:45
INSERT INTO `dbtest`.`t1`(`id`) VALUES (3); #start 36062 end 36233 time 2017-03-15 11:47:45
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=1 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=2 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=3 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
(2)解析某幾個(gè)binlog相應(yīng)的表t,t1操作記錄

點(diǎn)擊(此處)折疊或打開

  1. (root:localhost:Wed Mar 15 15:01:01 2017)[dbtest]>flush logs;

  2. Query OK, 0 rows affected (0.00 sec)


  3. (root:localhost:Wed Mar 15 15:01:09 2017)[dbtest]>show master status \G

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

  5.              File: mysql-bin.000030

  6.          Position: 120

  7.      Binlog_Do_DB:

  8.  Binlog_Ignore_DB:

  9. Executed_Gtid_Set:

  10. 1 row in set (0.00 sec)

  11. (root:localhost:Wed Mar 15 15:01:16 2017)[dbtest]>delete from t1;

  12. Query OK, 3 rows affected (0.00 sec)


  13. (root:localhost:Wed Mar 15 15:01:51 2017)[dbtest]>create table t2(id int);

  14. Query OK, 0 rows affected (0.00 sec)


  15. (root:localhost:Wed Mar 15 15:02:03 2017)[dbtest]>insert into t2 select * from t;

  16. Query OK, 3 rows affected (0.01 sec)

  17. Records: 3  Duplicates: 0  Warnings: 0

##特別注的是,如果值解析特定表的sql,DDL全部解析,DML過濾相應(yīng)的表SQL
[root@node1 mysql]# binlog2sql  -h20.0.1.10  -P3306 -udb_user -p'abc.123' -ddbtest -t t t1 --start-file='mysql-bin.000028' --stop-file='mysql-bin.000030'
USE dbtest;
DROP TABLE `t1` /* generated by server */;
USE dbtest;
DROP TABLE `T` /* generated by server */;
USE dbtest;
DROP TABLE `T1` /* generated by server */;
USE dbtest;
DROP TABLE `t2` /* generated by server */;
USE dbtest;
CREATE TABLE `t1` (
  `id` int(11) DEFAULT NULL
);
INSERT INTO `dbtest`.`t1`(`id`) VALUES (1); #start 36062 end 36233 time 2017-03-15 11:47:45
INSERT INTO `dbtest`.`t1`(`id`) VALUES (2); #start 36062 end 36233 time 2017-03-15 11:47:45
INSERT INTO `dbtest`.`t1`(`id`) VALUES (3); #start 36062 end 36233 time 2017-03-15 11:47:45
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=1 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=2 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=11 WHERE `id`=3 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
DELETE FROM `dbtest`.`t1` WHERE `id`=11 LIMIT 1; #start 10116 end 10287 time 2017-03-15 15:01:51
DELETE FROM `dbtest`.`t1` WHERE `id`=11 LIMIT 1; #start 10116 end 10287 time 2017-03-15 15:01:51
DELETE FROM `dbtest`.`t1` WHERE `id`=11 LIMIT 1; #start 10116 end 10287 time 2017-03-15 15:01:51
USE dbtest;
create table t2(id int);
(3)數(shù)據(jù)庫(kù)回滾
##通過-B或者--flashback參數(shù)解析回滾的SQL,但從解析內(nèi)容看,也是只解析DML

[root@node1 mysql]# binlog2sql --flashback   -h20.0.1.10  -P3306 -udb_user -p'abc.123' -ddbtest -tt -tt1  --start-file='mysql-bin.000028' --stop-file='mysql-bin.000030'           
INSERT INTO `dbtest`.`t1`(`id`) VALUES (11); #start 10116 end 10287 time 2017-03-15 15:01:51
INSERT INTO `dbtest`.`t1`(`id`) VALUES (11); #start 10116 end 10287 time 2017-03-15 15:01:51
INSERT INTO `dbtest`.`t1`(`id`) VALUES (11); #start 10116 end 10287 time 2017-03-15 15:01:51
UPDATE `dbtest`.`t1` SET `id`=3 WHERE `id`=11 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=2 WHERE `id`=11 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
UPDATE `dbtest`.`t1` SET `id`=1 WHERE `id`=11 LIMIT 1; #start 36625 end 36812 time 2017-03-15 11:48:12
DELETE FROM `dbtest`.`t1` WHERE `id`=3 LIMIT 1; #start 36062 end 36233 time 2017-03-15 11:47:45
DELETE FROM `dbtest`.`t1` WHERE `id`=2 LIMIT 1; #start 36062 end 36233 time 2017-03-15 11:47:45
DELETE FROM `dbtest`.`t1` WHERE `id`=1 LIMIT 1; #start 36062 end 36233 time 2017-03-15 11:47:45
四、知識(shí)擴(kuò)展
1、binlog種類以及其優(yōu)缺點(diǎn)
參考:

(1)Statement:每一條會(huì)修改數(shù)據(jù)的sql都會(huì)記錄在binlog中。
    優(yōu)點(diǎn):不需要記錄每一行的變化,減少了binlog日志量,節(jié)約了IO,提高性能。(相比row能節(jié)約多少性能與日志量,這個(gè)取決于應(yīng)用的SQL情況,正常同一條記錄修改或者插入row格式所產(chǎn)生的日志量還小于Statement產(chǎn)生的日志量,但是考慮到如果帶條件的update操作,以及整表刪除,alter表等操作,ROW格式會(huì)產(chǎn)生大量日志,因此在考慮是否使用ROW格式日志時(shí)應(yīng)該跟據(jù)應(yīng)用的實(shí)際情況,其所產(chǎn)生的日志量會(huì)增加多少,以及帶來的IO性能問題。)
    缺點(diǎn):由于記錄的只是執(zhí)行語句,為了這些語句能在slave上正確運(yùn)行,因此還必須記錄每條語句在執(zhí)行的時(shí)候的一些相關(guān)信息,以保證所有語句能在slave得到和在master端執(zhí)行時(shí)候相同 的結(jié)果。另外mysql 的復(fù)制,像一些特定函數(shù)功能,slave可與master上要保持一致會(huì)有很多相關(guān)問題(如sleep()函數(shù), last_insert_id(),以及user-defined functions(udf)會(huì)出現(xiàn)問題).使用以下函數(shù)的語句也無法被復(fù)制:LOAD_FILE()、UUID()、USER()、FOUND_ROWS()、SYSDATE() (除非啟動(dòng)時(shí)啟用了 --sysdate-is-now 選項(xiàng)),同時(shí)在INSERT ...SELECT 會(huì)產(chǎn)生比 RBR 更多的行級(jí)鎖
(2)Row:不記錄sql語句上下文相關(guān)信息,僅保存哪條記錄被修改。
    優(yōu)點(diǎn): binlog中可以不記錄執(zhí)行的sql語句的上下文相關(guān)的信息,僅需要記錄那一條記錄被修改成什么了。所以rowlevel的日志內(nèi)容會(huì)非常清楚的記錄下每一行數(shù)據(jù)修改的細(xì)節(jié)。而且不會(huì)出現(xiàn)某些特定情況下的存儲(chǔ)過程,或function,以及trigger的調(diào)用和觸發(fā)無法被正確復(fù)制的問題
    缺點(diǎn):所有的執(zhí)行的語句當(dāng)記錄到日志中的時(shí)候,都將以每行記錄的修改來記錄,這樣可能會(huì)產(chǎn)生大量的日志內(nèi)容,比如一條update語句,修改多條記錄,則binlog中每一條修改都會(huì)有記錄,這樣造成binlog日志量會(huì)很大,特別是當(dāng)執(zhí)行alter table之類的語句的時(shí)候,由于表結(jié)構(gòu)修改,每條記錄都發(fā)生改變,那么該表每一條記錄都會(huì)記錄到日志中。
(3)Mixed: 是以上兩種level的混合使用,一般的語句修改使用statment格式保存binlog,如一些函數(shù),statement無法完成主從復(fù)制的操作,則采用row格式保存binlog,MySQL會(huì)根據(jù)執(zhí)行的每一條具體的sql語句來區(qū)分對(duì)待記錄的日志形式,也就是在Statement和Row之間選擇一種.新版本的MySQL中隊(duì)row level模式也被做了優(yōu)化,并不是所有的修改都會(huì)以row level來記錄,像遇到表結(jié)構(gòu)變更的時(shí)候就會(huì)以statement模式來記錄。至于update或者delete等修改數(shù)據(jù)的語句,還是會(huì)記錄所有行的變更。
2、binlog相關(guān)配置參數(shù)
log_bin:設(shè)置此參數(shù)表示啟用binlog功能,并指定路徑名稱
log_bin_index:設(shè)置此參數(shù)是指定二進(jìn)制索引文件的路徑與名稱
binlog_do_db:此參數(shù)表示只記錄指定數(shù)據(jù)庫(kù)的二進(jìn)制日志
binlog_ignore_db:此參數(shù)表示不記錄指定的數(shù)據(jù)庫(kù)的二進(jìn)制日志
max_binlog_cache_size:此參數(shù)表示binlog使用的內(nèi)存最大的尺寸
binlog_cache_size:此參數(shù)表示binlog使用的內(nèi)存大小,可以通過狀態(tài)變量binlog_cache_use和binlog_cache_disk_use來幫助測(cè)試。
binlog_cache_use:使用二進(jìn)制日志緩存的事務(wù)數(shù)量
binlog_cache_disk_use:使用二進(jìn)制日志緩存但超過binlog_cache_size值并使用臨時(shí)文件來保存事務(wù)中的語句的事務(wù)數(shù)量
max_binlog_size:Binlog最大值,最大和默認(rèn)值是1GB,該設(shè)置并不能嚴(yán)格控制Binlog的大小,尤其是Binlog比較靠近最大值而又遇到一個(gè)比較大事務(wù)時(shí),為了保證事務(wù)的完整性,不可能做切換日志的動(dòng)作,只能將該事務(wù)的所有SQL都記錄進(jìn)當(dāng)前日志,直到事務(wù)結(jié)束
sync_binlog:這個(gè)參數(shù)直接影響mysql的性能和完整性。sync_binlog=0表示當(dāng)事務(wù)提交后,Mysql僅僅是將binlog_cache中的數(shù)據(jù)寫入Binlog文件,但不執(zhí)行fsync之類的磁盤 同步指令通知文件系統(tǒng)將緩存刷新到磁盤,而讓Filesystem自行決定什么時(shí)候來做同步,這個(gè)是性能最好的。sync_binlog=n,在進(jìn)行n次事務(wù)提交以后,Mysql將執(zhí)行一次fsync之類的磁盤同步指令,同志文件系統(tǒng)將Binlog文件緩存刷新到磁盤。Mysql中默認(rèn)的設(shè)置是sync_binlog=0,即不作任何強(qiáng)制性的磁盤刷新指令,這時(shí)性能是最好的,但風(fēng)險(xiǎn)也是最大的。一旦系統(tǒng)繃Crash,在文件系統(tǒng)緩存中的所有Binlog信息都會(huì)丟失
binlog_format:binlog日志格式,statement/row/mixed
binlog_row_image:其是在5.6之后有的參數(shù),F(xiàn)ULL記錄每一行的變更,minimal只記錄影響后的行,前提是row模式。
3、binlog刪除方法
reset master;   ##刪除master的binlog
reset slave;    ##刪除slave的中繼日志,reset slave all
purge master logs before '2016-03-15 10:00:00';  ##刪除指定日期以前的日志索引中binlog日志文件
purge master logs to 'binlog.000001';  ##刪除指定日志文件的日志索引中binlog日志文件
4、mysqlbinlog解析row模式的binlog日志
mysqlbinlog --base64-output=decode-rows -v --start-datetime='2016-07-13 10:00:00' --stop-datetime='2016-07-13 10:40:00'  mysql-bin.000021
5、主從binlog和relaylog文件內(nèi)容
主庫(kù):
    File: binlog.007247                   ##主庫(kù)當(dāng)前寫入的binlog文件
    Position: 132941350                ##主庫(kù)當(dāng)前寫入的binlog文件position
從庫(kù):
    Master_Log_File: binlog.007247                    ##從庫(kù)io thread當(dāng)前讀取的主庫(kù)binlog文件
    Read_Master_Log_Pos: 100309902               ##從庫(kù)io thread當(dāng)前讀取的主庫(kù)binlog文件的position
    Relay_Log_File: mysql-relay-bin.025950          ##從庫(kù)SQL thread當(dāng)前寫入的relay-log文件
    Relay_Log_Pos: 29008629                           ##從庫(kù)SQL thread當(dāng)前寫入的replay-log文件的position
    Relay_Master_Log_File: binlog.007243           ##當(dāng)前執(zhí)行的replay-log對(duì)應(yīng)的主庫(kù)binlog文件
    Exec_Master_Log_Pos: 565883515               ##當(dāng)前執(zhí)行的binlog文件的position
    Relay_Log_Space: 4395318217                    ##讀取與執(zhí)行的relay-log間隔
    cat relay-log.info                 ##relay-log執(zhí)行binlog信息
    ./mysql-relay-bin.025950            ##當(dāng)前SQL thread寫入的relay-log文件
    29008629                    ##當(dāng)前SQL thread寫入的relay-log文件的position
    binlog.007243                    ##當(dāng)前執(zhí)行的relay-log文件對(duì)應(yīng)的binlog 文件
    565883515                    ##當(dāng)前執(zhí)行的relay-log文件對(duì)應(yīng)的binlog 文件的position
    cat master.info                 ##主從同步信息記錄文件
    binlog.007247                    ##當(dāng)前讀取的主庫(kù)binlog文件
    372008635                    ##當(dāng)前讀取的主庫(kù)binlog文件對(duì)應(yīng)的position

關(guān)于“MYSQL中Binglog分析利器binlog2sql怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI