0
点赞
收藏
分享

微信扫一扫

mysql binlog常用操作

青鸾惊鸿 2022-04-27 阅读 50
binlogmysql

一.查看 binlog 基本信息

binlog文件的位置配置可在 /etc/my.cnf 配置和查看

0. 登录 mysql

mysql -h localhost -u root -p

1.查看binlog文件列表

进入mysql命令行:

show binary logs;

在这里插入图片描述

2.查看当前正在写入的binlog文件

show master status;

在这里插入图片描述

3. 查看binlog事件信息

show binlog events in 'bin-log.000004';

4.查看 binlog 文件单个大小

默认大小为 1G

show variables like '%binlog%';

二.mysqlbinlog 命令

1. 查看 binlog 文件

例如:

mysqlbinlog bin-log.000115

在这里插入图片描述

2.查看某个范围的binlog

有四个参数可以选择性加入:

# 开始pos点 
--start-position=953

# 结束pos点 
--stop-position=1437

# 起始时间点:
--start-datetime="2022-03-25 00:00:00"

# 结束时间点:
--stop-datetime="2022-03-26 00:00:00" 

查看时间范围的 binlog

mysqlbinlog --start-datetime="2022-04-06 00:00:00" --stop-datetime="2022-04-06 01:00:00"  bin-log.000114

查看 pos 范围的 binlog

mysqlbinlog --start-position=3648579 --stop-position=3656656  bin-log.000115

2.查看解码后的 binlog 文件

mysqlbinlog 默认只能查看到 base-64 编码的信息, 添加 --base64-output=value 选项可以进行解码等操作:

3.1 生成带注释的语句

mysqlbinlog -v --base64-output=DECODE-ROWS --start-position=3648579 --stop-position=3656656  bin-log.000115
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 3648579
#220413 10:19:50 server id 1  end_log_pos 3648707 CRC32 0xf0526728 	Table_map: `docloud`.`das_layer` mapped to number 410
# at 3648707
#220413 10:19:50 server id 1  end_log_pos 3656528 CRC32 0x6afac713 	Write_rows: table id 410 flags: STMT_END_F
### INSERT INTO `docloud`.`das_layer`
### SET
###   @1=55851
###   @2='粤港澳经济联系'
###   @3=6
###   @4='{"dataSource":{"page":0,"size":0,"id":"326d3ec6b2fe4cbeb7dc2684c3f5d767","typeId":"5b1b524c32a5435e8247b046fa80b7d2","name":"粤港澳经济联系","pubTime":null,"updateTime":null,"content":"","isPublic":true,"dataUrl":"/Users/xskj/files/17a435b9a73a44a49db50c41be9712f4/20190604/9f18079714604a7da0df79b8816ec0e7-粤港澳经济联系/粤港澳经济联系.shp","dataSize":253,"publisher":"17a435b9a73a44a49db50c41be9712f4","updateUser":"17a435b9a73a44a49db50c41be9712f4","dataFrom":null,"updateRate":null,"region":null,"dataType":"shp","dataCql":null,"dataParam":null,"lonLat":null,"typeName":"示例数据","search":null,"pubTimeStr":"2019-06-04 17:10:35","updateTimeStr":"2019-06-04 17:10:35","tagIds":null,"dataTagsList":[{"id":"7cbeb52b9a2c49078c076624fe03a5d6","tagName":"经济"},{"id":"5712ffe23f344cf0aa87343455613d4f","tagName":"粤港澳"}],"dataTagList":null,"parentTypeId":"0","parentTypeName":null,"tableHead":null,"geomesaName":"99af728377114dc3a5d9f84451ca1d7e","typeIds":null,"catalog":"17a435b9a73a44a49db50c41be9712f4","isGeo":1,"geoType":"MultiLineString","fileSize":null,"timeKey":null,"order":null,"workspaceId":null,"attrTable":"34612cd0cca848938ccd2e80036ede43","datasourceId":"a381b680069b4841b5c9b872fb947bea","key":"9table"},"fortmatChart":{"catalog":"","sourceType":7,"features":"","dimension":[],"where":{"mode":1,"conditions":[]}}}'
###   @5=''
###   @6=0
###   @7='b1ce0b8228df4534bdedc751a09d73b4'
###   @8='12188'
###   @9='{"lineStyle":{"color":{"type":2,"feild":"强度","color":"rgb(0,53,177)","colorArray":["rgba(2,22,92,1)","rgba(11,54,177,1)","rgba(3,55,219,1)","rgba(79,34,243,1)","rgba(136,87,238,1)","rgba(238,170,35,1)","rgba(250,225,176,1)"],"opacity":1,"antitone":false},"radius":{"type":2,"feild":"强度","radiusScale":0.2,"radiusMinPixels":0,"radiusMaxPixels":15},"customColor":{"skin":"customColor1","arrayColors":[{"colorLength":7,"id":1,"selected":1,"thisColorAll":["rgba(250,225,176,1)","rgba(238,170,35,1)","rgba(136,87,238,1)","rgba(79,34,243,1)","rgba(3,55,219,1)","rgba(11,54,177,1)","rgba(2,22,92,1)"]},{"id":2,"selected":0,"colorLength":6,"thisColorAll":["rgb(207,120,34)","rgb(242,19,242)","rgb(179,26,45)","rgb(250,130,138)","rgb(199,78,85)","rgb(47,221,110)"]}]},"customColorState":true},"scatterStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":100,"radiusScale":1,"radiusMinPixels":1,"radiusMaxPixels":100},"control":true},"heatStyle":{"color":{"feild":"","opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"]},"radius":{"radius":10},"antitone":false},"heartBeatStyle":{"autoAvoid":true,"animation":{"scatterStyleType":2,"scatterAimatedType":1,"scatterSpeed":5},"color":{"type":1,"feild":"","color":"rgb(251,25,120)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":2,"radiusScale":1,"radiusMinPixels":1,"radiusMaxPixels":100}},"cubeStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"extruded":false,"elevationScale":0.1},"aggregation":{"feild":"","type":1},"customColorState":false,"customColor":{"skin":"customColor1","arrayColors":[{"colorLength":6,"id":1,"selected":1,"thisColorAll":["rgb(120,99,182)","rgb(230,121,220)","rgb(97,213,179)","rgb(11,125,120)","rgb(74,129,18)","rgb(25,213,160)"]}]}},"gridStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"elevationScale":0.1},"aggregation":{"feild":"","type":1}},"hexagonStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"extruded":false,"elevationScale":0.1}},"arcStyle":{"dataState":{"OXState":"","OYState":"","DXState":"","DYState":""},"color":{"type":1,"feild":"","Ocolor":"rgb(0,53,177)","Dcolor":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"line":{"type":1,"feild":"","radiusScale":2,"radiusMinPixels":1,"radiusMaxPixels":100}},"regionStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"line":{"type":1,"feild":"","lineWidthScale":0.1,"lineWidthMinPixels":0,"lineWidthMaxPixels":10},"height":{"extruded":false,"type":1,"feild":"","heightScale":0.1,"heightMinPixels":0,"heightMaxPixels":1}},"sizeScatterStyle":{"color":{"type":2,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"clusterRadius":25,"radiusMinPixels":10,"radiusMaxPixels":50},"text":{"show":true,"fontSize":12,"color":"rgb(0,53,177)"}},"iconStyle":{"iconUrl":{"type":1,"feild":"","url":"5dd28575c37b2a4fb5b612dc"},"billboard":true,"color":{"state":false,"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"size":{"sizeUnits":"pixels","type":1,"feild":"","size":5,"sizeScale":2,"sizeMinPixels":1,"sizeMaxPixels":100},"anchorHeight":{"height":13,"type":1,"feild":"","heightScale":2,"heightMinPixels":1,"heightMaxPixels":100},"anchorWidth":{"width":0,"type":1,"feild":"","widthScale":2,"widthMinPixels":1,"widthMaxPixels":100},"angle":{"angle":0,"type":1,"feild":"","angleScale":2,"angleMinPixels":1,"angleMaxPixels":360}},"tripsStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":100,"radiusScale":2,"radiusMinPixels":1,"radiusMaxPixels":100},"size":{"type":1,"feild":"","size":100,"sizeScale":2,"sizeMinPixels":1,"sizeMaxPixels":100},"time":{"addtime":100,"frequencyTime":20},"trips":{"feild":""}},"mapdirectionVisible":true}'
###   @10='326d3ec6b2fe4cbeb7dc2684c3f5d767'
###   @11='2'
###   @12=''
###   @13=7104
###   @14='{"width":1307,"height":1011,"latitude":22.847174580757454,"longitude":113.20648330435088,"zoom":6.940217768055615,"bearing":10.884382022604372,"pitch":41.42135403943822,"altitude":1.5,"maxZoom":16,"minZoom":0,"maxPitch":60,"minPitch":0,"position":[0,0,0],"transitionDuration":0,"cameraLockType":1,"cameraLock":false}'
###   @15=''
###   @16='1'
###   @17='2022-04-13 10:19:50'
###   @18=1
###   @19=''
###   @20='2022-04-13 10:19:50'
###   @21=''
###   @22=0
###   @23=0
###   @24=2
###   @25=''
###   @26='{"minZoom":0,"maxZoom":24}'
###   @27='additive'
###   @28='{"lineSection":{"color":{"type":1,"colorSectionArr":[],"colorSectionArr2":[]}},"scatterSection":{"color":{"type":1,"colorSectionArr":[]}},"heatSection":{"color":{"type":1,"colorSectionArr":[]}},"cubeSection":{"color":{"type":1,"colorSectionArr":[]}},"gridSection":{"color":{"otype":1,"colorSectionArr":[]}},"hexagonSection":{"color":{"type":1,"colorSectionArr":[]}},"arcSection":{"color":{"type":1,"colorSectionArr":[]}},"regionSection":{"color":{"type":1,"colorSectionArr":[]}},"sizeScatterSection":{"color":{"type":1,"colorSectionArr":[]}},"iconSection":{"color":{"type":1,"colorSectionArr":[]}},"tripsSection":{"color":{"type":1,"colorSectionArr":[]}}}'
###   @29=0
###   @30=2
###   @31=1
###   @32=1
###   @33=''
# at 3656528
#220413 10:19:50 server id 1  end_log_pos 3656656 CRC32 0xa0e70fe3 	Table_map: `docloud`.`das_layer` mapped to number 410
WARNING: The range of printed events ends with a row event or a table map event that does not have the STMT_END_F flag set. This might be because the last statement was not fully written to the log, or because you are using a --stop-position or --stop-datetime that refers to an event in the middle of a statement. The event(s) from the partial statement have not been written to output.
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

3.2 生成字段的类型、长度、是否为null等属性信息

mysqlbinlog -v -v --base64-output=DECODE-ROWS --start-position=3648579 --stop-position=3656656  bin-log.000115
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 3648579
#220413 10:19:50 server id 1  end_log_pos 3648707 CRC32 0xf0526728 	Table_map: `docloud`.`das_layer` mapped to number 410
# at 3648707
#220413 10:19:50 server id 1  end_log_pos 3656528 CRC32 0x6afac713 	Write_rows: table id 410 flags: STMT_END_F
### INSERT INTO `docloud`.`das_layer`
### SET
###   @1=55851 /* INT meta=0 nullable=0 is_null=0 */
###   @2='粤港澳经济联系' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @3=6 /* INT meta=0 nullable=1 is_null=0 */
###   @4='{"dataSource":{"page":0,"size":0,"id":"326d3ec6b2fe4cbeb7dc2684c3f5d767","typeId":"5b1b524c32a5435e8247b046fa80b7d2","name":"粤港澳经济联系","pubTime":null,"updateTime":null,"content":"","isPublic":true,"dataUrl":"/Users/xskj/files/17a435b9a73a44a49db50c41be9712f4/20190604/9f18079714604a7da0df79b8816ec0e7-粤港澳经济联系/粤港澳经济联系.shp","dataSize":253,"publisher":"17a435b9a73a44a49db50c41be9712f4","updateUser":"17a435b9a73a44a49db50c41be9712f4","dataFrom":null,"updateRate":null,"region":null,"dataType":"shp","dataCql":null,"dataParam":null,"lonLat":null,"typeName":"示例数据","search":null,"pubTimeStr":"2019-06-04 17:10:35","updateTimeStr":"2019-06-04 17:10:35","tagIds":null,"dataTagsList":[{"id":"7cbeb52b9a2c49078c076624fe03a5d6","tagName":"经济"},{"id":"5712ffe23f344cf0aa87343455613d4f","tagName":"粤港澳"}],"dataTagList":null,"parentTypeId":"0","parentTypeName":null,"tableHead":null,"geomesaName":"99af728377114dc3a5d9f84451ca1d7e","typeIds":null,"catalog":"17a435b9a73a44a49db50c41be9712f4","isGeo":1,"geoType":"MultiLineString","fileSize":null,"timeKey":null,"order":null,"workspaceId":null,"attrTable":"34612cd0cca848938ccd2e80036ede43","datasourceId":"a381b680069b4841b5c9b872fb947bea","key":"9table"},"fortmatChart":{"catalog":"","sourceType":7,"features":"","dimension":[],"where":{"mode":1,"conditions":[]}}}' /* BLOB/TEXT meta=2 nullable=1 is_null=0 */
###   @5='' /* VARSTRING(384) meta=384 nullable=1 is_null=0 */
###   @6=0 /* INT meta=0 nullable=1 is_null=0 */
###   @7='b1ce0b8228df4534bdedc751a09d73b4' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */
###   @8='12188' /* VARSTRING(96) meta=96 nullable=0 is_null=0 */
###   @9='{"lineStyle":{"color":{"type":2,"feild":"强度","color":"rgb(0,53,177)","colorArray":["rgba(2,22,92,1)","rgba(11,54,177,1)","rgba(3,55,219,1)","rgba(79,34,243,1)","rgba(136,87,238,1)","rgba(238,170,35,1)","rgba(250,225,176,1)"],"opacity":1,"antitone":false},"radius":{"type":2,"feild":"强度","radiusScale":0.2,"radiusMinPixels":0,"radiusMaxPixels":15},"customColor":{"skin":"customColor1","arrayColors":[{"colorLength":7,"id":1,"selected":1,"thisColorAll":["rgba(250,225,176,1)","rgba(238,170,35,1)","rgba(136,87,238,1)","rgba(79,34,243,1)","rgba(3,55,219,1)","rgba(11,54,177,1)","rgba(2,22,92,1)"]},{"id":2,"selected":0,"colorLength":6,"thisColorAll":["rgb(207,120,34)","rgb(242,19,242)","rgb(179,26,45)","rgb(250,130,138)","rgb(199,78,85)","rgb(47,221,110)"]}]},"customColorState":true},"scatterStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":100,"radiusScale":1,"radiusMinPixels":1,"radiusMaxPixels":100},"control":true},"heatStyle":{"color":{"feild":"","opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"]},"radius":{"radius":10},"antitone":false},"heartBeatStyle":{"autoAvoid":true,"animation":{"scatterStyleType":2,"scatterAimatedType":1,"scatterSpeed":5},"color":{"type":1,"feild":"","color":"rgb(251,25,120)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":2,"radiusScale":1,"radiusMinPixels":1,"radiusMaxPixels":100}},"cubeStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"extruded":false,"elevationScale":0.1},"aggregation":{"feild":"","type":1},"customColorState":false,"customColor":{"skin":"customColor1","arrayColors":[{"colorLength":6,"id":1,"selected":1,"thisColorAll":["rgb(120,99,182)","rgb(230,121,220)","rgb(97,213,179)","rgb(11,125,120)","rgb(74,129,18)","rgb(25,213,160)"]}]}},"gridStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"elevationScale":0.1},"aggregation":{"feild":"","type":1}},"hexagonStyle":{"color":{"opacity":1,"color":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"antitone":false},"radius":{"cellSize":1,"coverage":0.9},"height":{"extruded":false,"elevationScale":0.1}},"arcStyle":{"dataState":{"OXState":"","OYState":"","DXState":"","DYState":""},"color":{"type":1,"feild":"","Ocolor":"rgb(0,53,177)","Dcolor":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"line":{"type":1,"feild":"","radiusScale":2,"radiusMinPixels":1,"radiusMaxPixels":100}},"regionStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"line":{"type":1,"feild":"","lineWidthScale":0.1,"lineWidthMinPixels":0,"lineWidthMaxPixels":10},"height":{"extruded":false,"type":1,"feild":"","heightScale":0.1,"heightMinPixels":0,"heightMaxPixels":1}},"sizeScatterStyle":{"color":{"type":2,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"clusterRadius":25,"radiusMinPixels":10,"radiusMaxPixels":50},"text":{"show":true,"fontSize":12,"color":"rgb(0,53,177)"}},"iconStyle":{"iconUrl":{"type":1,"feild":"","url":"5dd28575c37b2a4fb5b612dc"},"billboard":true,"color":{"state":false,"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"size":{"sizeUnits":"pixels","type":1,"feild":"","size":5,"sizeScale":2,"sizeMinPixels":1,"sizeMaxPixels":100},"anchorHeight":{"height":13,"type":1,"feild":"","heightScale":2,"heightMinPixels":1,"heightMaxPixels":100},"anchorWidth":{"width":0,"type":1,"feild":"","widthScale":2,"widthMinPixels":1,"widthMaxPixels":100},"angle":{"angle":0,"type":1,"feild":"","angleScale":2,"angleMinPixels":1,"angleMaxPixels":360}},"tripsStyle":{"color":{"type":1,"feild":"","color":"rgb(0,53,177)","colorArray":["rgb(54,98,206)","rgb(156,185,244)","rgb(37,59,103)","rgb(204,88,73)","rgb(34,30,30)","rgb(76,159,236)"],"opacity":1,"antitone":false},"radius":{"type":1,"feild":"","radius":100,"radiusScale":2,"radiusMinPixels":1,"radiusMaxPixels":100},"size":{"type":1,"feild":"","size":100,"sizeScale":2,"sizeMinPixels":1,"sizeMaxPixels":100},"time":{"addtime":100,"frequencyTime":20},"trips":{"feild":""}},"mapdirectionVisible":true}' /* BLOB/TEXT meta=2 nullable=1 is_null=0 */
###   @10='326d3ec6b2fe4cbeb7dc2684c3f5d767' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
###   @11='2' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @12='' /* MEDIUMBLOB/MEDIUMTEXT meta=3 nullable=1 is_null=0 */
###   @13=7104 /* INT meta=0 nullable=1 is_null=0 */
###   @14='{"width":1307,"height":1011,"latitude":22.847174580757454,"longitude":113.20648330435088,"zoom":6.940217768055615,"bearing":10.884382022604372,"pitch":41.42135403943822,"altitude":1.5,"maxZoom":16,"minZoom":0,"maxPitch":60,"minPitch":0,"position":[0,0,0],"transitionDuration":0,"cameraLockType":1,"cameraLock":false}' /* VARSTRING(3072) meta=3072 nullable=1 is_null=0 */
###   @15='' /* BLOB/TEXT meta=2 nullable=1 is_null=0 */
###   @16='1' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @17='2022-04-13 10:19:50' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
###   @18=1 /* INT meta=0 nullable=1 is_null=0 */
###   @19='' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
###   @20='2022-04-13 10:19:50' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
###   @21='' /* BLOB/TEXT meta=2 nullable=1 is_null=0 */
###   @22=0 /* INT meta=0 nullable=1 is_null=0 */
###   @23=0 /* INT meta=0 nullable=1 is_null=0 */
###   @24=2 /* INT meta=0 nullable=1 is_null=0 */
###   @25='' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
###   @26='{"minZoom":0,"maxZoom":24}' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @27='additive' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @28='{"lineSection":{"color":{"type":1,"colorSectionArr":[],"colorSectionArr2":[]}},"scatterSection":{"color":{"type":1,"colorSectionArr":[]}},"heatSection":{"color":{"type":1,"colorSectionArr":[]}},"cubeSection":{"color":{"type":1,"colorSectionArr":[]}},"gridSection":{"color":{"otype":1,"colorSectionArr":[]}},"hexagonSection":{"color":{"type":1,"colorSectionArr":[]}},"arcSection":{"color":{"type":1,"colorSectionArr":[]}},"regionSection":{"color":{"type":1,"colorSectionArr":[]}},"sizeScatterSection":{"color":{"type":1,"colorSectionArr":[]}},"iconSection":{"color":{"type":1,"colorSectionArr":[]}},"tripsSection":{"color":{"type":1,"colorSectionArr":[]}}}' /* VARSTRING(6144) meta=6144 nullable=1 is_null=0 */
###   @29=0 /* TINYINT meta=0 nullable=1 is_null=0 */
###   @30=2 /* TINYINT meta=0 nullable=1 is_null=0 */
###   @31=1 /* INT meta=0 nullable=1 is_null=0 */
###   @32=1 /* TINYINT meta=0 nullable=1 is_null=0 */
###   @33='' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
# at 3656528
#220413 10:19:50 server id 1  end_log_pos 3656656 CRC32 0xa0e70fe3 	Table_map: `docloud`.`das_layer` mapped to number 410
WARNING: The range of printed events ends with a row event or a table map event that does not have the STMT_END_F flag set. This might be because the last statement was not fully written to the log, or because you are using a --stop-position or --stop-datetime that refers to an event in the middle of a statement. The event(s) from the partial statement have not been written to output.
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

4. 输出 binlog 日志到指定文件

mysqlbinlog --start-position=3648579 --stop-position=3656656 bin-log.000115 > test.log

或者

mysqlbinlog --start-position=3648579 --stop-position=3656656 bin-log.000115 --result-file=test2.log

同样可以加 -v -v --base64-output=DECODE-ROWS 等参数

5. 输出 binlog 日志到压缩文件中

mysqlbinlog --start-position=3648579 --stop-position=3656656 bin-log.000115|gzip > test.zip

三. 删除或重置 binlog 日志

0.登录查看 binlog 日志信息

登录mysql

mysql -h localhost -u root -p
show binary logs;

1. 删除所有binlog日志,新日志编号从头开始

RESET MASTER;

2.删除 bin-log.000004 之前所有日志

PURGE MASTER LOGS TO 'bin-log.000004';

3.删除 2021-05-01 00:00:00 之前产生的所有日志

PURGE MASTER LOGS BEFORE '2020-04-24 22:00:00';

4.在 my.cnf 配置文件中指定日志过期时间

expire_logs_days=30

5.开启一个新的 binlog 日志文件

 flush logs;

每次服务器(数据库)重启,服务器会调用 flush logs; 新创建一个binlog日志

四.从 binlog 中恢复数据

1.找到要操作的日志文件

show binlog events in 'mysql-bin.000001';

在这里插入图片描述

我们可以从中找到 pos 信息

2.按 pos 点进行数据恢复

不指定库恢复整个 binlog 日志的数据

mysqlbinlog --start-position=322 --stop-position=9424573 bin-log.000002 | mysql -uroot -p123zxcv

3.按日期进行数据恢复

查看 binlog 日志

mysqlbinlog -vv --base64-output=decode-rows bin-log.000002

不指定库恢复整个 binlog 日志的数据

mysqlbinlog --start-datetime='2022-04-24 16:08:00' --stop-datetime='2022-04-24 16:28:00' bin-log.000002 | mysql -uroot -p123zxcv

4.指定库进行数据恢复

指定库恢复整个 binlog 日志的数据

按 pos 点:

mysqlbinlog --start-position=4 --stop-position=5010 --database=abc bin-log.000004 | mysql -uroot -p123zxcv

按时间:

mysqlbinlog --start-datetime='2022-04-24 16:08:00' --stop-datetime='2022-04-24 16:28:00' --database=abc bin-log.000002 | mysql -uroot -p123zxcv
举报

相关推荐

mysql -binlog

mysql 常用操作

MySQL常用操作

mysql binlog 配置

MySQL binlog详解

0 条评论