一.查看 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 选项可以进行解码等操作:

AUTO 或 UNSPEC: 在必要时自动显示 BINLOG 语句(即,用于格式描述事件和行事件)。如果没有给出 --base64-output 选项,则效果与 --base64-output = AUTO 相同。

NEVER: 不显示 BINLOG 语句

DECODE-ROWS: 通过配合–verbose 选项将行事件解码并显示为注释的SQL语句。使用参数–verbose(或-v),将生成带注释的语句,如果使用两次这个参数(如-v -v),会生成字段的类型、长度、是否为null等属性信息。

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常用操作相关推荐

  1. MySQL数据库常用操作(20221211)

    记录:360 场景:MySQL数据库常用操作,启动.重启.停止MySQL服务:创建用户.数据库.表.主键.索引.注释等.配置远程可连接.配置环境变量.常用系统表操作.常用命令行操作.表的增删改查等操作 ...

  2. php mysql 权重_PHP对MySql的常用操作

    关于PHP对MySql的常用操作 最近做网站,用PHP操作数据库也很多次了,但总是忘记,参考了网上的很多资料,算是整理记录下. 数据库操作类 实现数据库的连接,断开,以及请求: /** * Creat ...

  3. Windows下 MySQL命令 常用操作

    2019独角兽企业重金招聘Python工程师标准>>> Windows平台下MySQL常用操作与命令 (一)客户端连接MySQL数据库服务器 命令格式:mysql -h 数据库服务器 ...

  4. ubuntu下安装mysql及常用操作

    1.可通过ps -ef | grep mysql命令查看系统中是否有安装mysql 如果出现类似上述的页面,就证明是已经安装过了mysql,否则就是没有. 2.安装mysql 很简单,只需要键入如下命 ...

  5. Linux下MySql数据库常用操作

    1.显示数据库 show databases; 2.选择数据库 use 数据库名; 3.显示数据库中的表 show tables; 4.显示数据表的结构 describe 表名; 5.显示表中记录 S ...

  6. mysql binlog 常用的命令

    因为我在公司里面负责数据同步组件的相关工作,包括构建异地多活的工作,所以,需要先了解一下 MySQL binlog 的相关知识点.由于看过了好几遍了<高可用 MySQL > 这本经典的书籍 ...

  7. Mysql数据库常用操作整理

    0.说明 MySQL数据库是一个十分轻便的数据库管理系统,相比大型的数据库管理系统如Oracle,MySQL更拥有轻便.灵活.开发速度快的特色,更适用于中小型数据的存储与架构,被数以万计的网站采用.从 ...

  8. 聊一聊Elasticsearch和MySQL的常用操作

    前言 ElasticSearch,开源的搜索和数据分析引擎,也是名列前茅的 nosql. 很多时候会想拿它和关系型数据库做对比,严格上它们是没有太多可比性的. 不过把有的东西放在一起比较,会帮助我们快 ...

  9. MySQL的常用操作

    设置更改root密码 连接mysql mysql常用命令 mysql用户管理 常用sql语句 mysql数据库备份恢复 错误解决 1. 设置更改root密码 /usr/local/mysql/bin/ ...

  10. php面向对象封装mysql_php mysqli面向对象封装mysql数据库常用操作

    首先封装好mysql类 mysql.php class Mysql{ private static $host="localhost"; private static $user= ...

最新文章

  1. z营销新网站首页预览
  2. dfs时间复杂度_吊打DFS和BFS,什么情况下可以用二分?
  3. JS 关于(function( window, undefined ) {})(window)写法的理解
  4. java语言转换c语言,求助大神!!!JAVA转换成C语言
  5. 机器学习——支持向量机SVM之多分类问题
  6. [html] title与h1、b与strong、i与em的区别分别是什么?
  7. 【图像处理】U-Net中的重叠-切片(Overlap-tile)
  8. 大数据在各个行业的应用_大数据的应用领域有哪些
  9. php.ini路径设置、libmysql.dll加载等
  10. 已添加了具有相同键的项_减糖的另一种创新方案:不被计算为“添加糖”的水果泥...
  11. EDSR:Enhanced Deep Residual Networks for Single Image Super-Resolution
  12. 黑马程序员Java零基础视频教程(2022最新Java)B站视频学习笔记-Day6-方法
  13. 初识STM32与其选型
  14. 分享视频分析软件常用的几个C++库
  15. AutoCAD 命令定义
  16. Electron客户端的自动升级方案-2022版
  17. Android Studio中AndroidManifest.xml文件中application标签
  18. vbox虚拟机 做服务器,vbox虚拟机设置服务器(vbox虚拟机做服务器)
  19. 章文嵩:开放与高可用是阿里云角力海外市场的关键
  20. NVIDIA Tesla T4 GPU参数

热门文章

  1. 【Week 15 作业】A - ZJM 与霍格沃兹(必做)、B - ZJM 与生日礼物(选做)、C - ZJM 与纸条(选做)
  2. 从turtlesim到贪吃蛇……
  3. Python3 XML解析
  4. 抖音上热门的7大小技巧
  5. STL(标准模板库)
  6. 思岚A1M8激光雷达-ubuntu18.04-slam建图参考
  7. 关于银河麒麟服务器操作系统里使用TongWeb做为应用服务器出现的前台提交中文后台获取到的是乱码的问题处理思路
  8. freemarker制作word模板
  9. android 微博 登录,Android第三方登录之微博登录
  10. VVC学习之五:帧内预测——MPM列表建立