MySql binlog 是否包含事务边界?
Does the MySql binlog contain transaction boundaries?
如果我正在读取 MySql 二进制日志,我能否获得同一事务中发生哪些语句的指示?
有nothing built-in yet, but perhaps this page会提供一些帮助。他们提供了一个 awk
脚本,该脚本将解析二进制日志并提供事务详细信息,至少用于 row-based 复制。我们不喜欢 link-only 答案,所以我将 post 脚本本身放在这里:
startdate="2015-01-12 21:40:00"
stopdate="2015-01-12 21:45:00"
logfile="mysqld-bin.000023"
mysqlbinlog --base64-output=decode-rows -vv --start-datetime="$startdate" --stop-datetime="$stopdate" $logfile | awk \
'BEGIN {s_type=""; s_count=0;count=0;insert_count=0;update_count=0;delete_count=0;flag=0;} \
{if(match([=10=], /#15.*Table_map:.*mapped to number/)) {printf "Timestamp : " " " " Table : " $(NF-4); flag=1} \
else if (match([=10=], /(### INSERT INTO .*..*)/)) {count=count+1;insert_count=insert_count+1;s_type="INSERT"; s_count=s_count+1;} \
else if (match([=10=], /(### UPDATE .*..*)/)) {count=count+1;update_count=update_count+1;s_type="UPDATE"; s_count=s_count+1;} \
else if (match([=10=], /(### DELETE FROM .*..*)/)) {count=count+1;delete_count=delete_count+1;s_type="DELETE"; s_count=s_count+1;} \
else if (match([=10=], /^(# at) /) && flag==1 && s_count>0) {print " Query Type : "s_type " " s_count " row(s) affected" ;s_type=""; s_count=0; } \
else if (match([=10=], /^(COMMIT)/)) {print "[Transaction total : " count " Insert(s) : " insert_count " Update(s) : " update_count " Delete(s) : " \
delete_count "] \n+----------------------+----------------------+----------------------+----------------------+"; \
count=0;insert_count=0;update_count=0; delete_count=0;s_type=""; s_count=0; flag=0} } '
如果我正在读取 MySql 二进制日志,我能否获得同一事务中发生哪些语句的指示?
有nothing built-in yet, but perhaps this page会提供一些帮助。他们提供了一个 awk
脚本,该脚本将解析二进制日志并提供事务详细信息,至少用于 row-based 复制。我们不喜欢 link-only 答案,所以我将 post 脚本本身放在这里:
startdate="2015-01-12 21:40:00"
stopdate="2015-01-12 21:45:00"
logfile="mysqld-bin.000023"
mysqlbinlog --base64-output=decode-rows -vv --start-datetime="$startdate" --stop-datetime="$stopdate" $logfile | awk \
'BEGIN {s_type=""; s_count=0;count=0;insert_count=0;update_count=0;delete_count=0;flag=0;} \
{if(match([=10=], /#15.*Table_map:.*mapped to number/)) {printf "Timestamp : " " " " Table : " $(NF-4); flag=1} \
else if (match([=10=], /(### INSERT INTO .*..*)/)) {count=count+1;insert_count=insert_count+1;s_type="INSERT"; s_count=s_count+1;} \
else if (match([=10=], /(### UPDATE .*..*)/)) {count=count+1;update_count=update_count+1;s_type="UPDATE"; s_count=s_count+1;} \
else if (match([=10=], /(### DELETE FROM .*..*)/)) {count=count+1;delete_count=delete_count+1;s_type="DELETE"; s_count=s_count+1;} \
else if (match([=10=], /^(# at) /) && flag==1 && s_count>0) {print " Query Type : "s_type " " s_count " row(s) affected" ;s_type=""; s_count=0; } \
else if (match([=10=], /^(COMMIT)/)) {print "[Transaction total : " count " Insert(s) : " insert_count " Update(s) : " update_count " Delete(s) : " \
delete_count "] \n+----------------------+----------------------+----------------------+----------------------+"; \
count=0;insert_count=0;update_count=0; delete_count=0;s_type=""; s_count=0; flag=0} } '