当前位置: 首页 > news >正文

记录一次数据恢复,mysql8 - 义美

SHOW VARIABLES LIKE 'log_bin_basename';

Variable_name Value
log_bin_basename E:\environment\mysql-8.0.41-winx64\data\binlog

SHOW MASTER STATUS;

File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set
binlog.000046 1889087

保存日志,(E:\environment\mysql-8.0.41-winx64\data\binlog.000046  这个是日志的路径)
mysqlbinlog --no-defaults --start-datetime="2025-11-03 16:40:00" --stop-datetime="2025-11-03 17:10:00" --base64-output=DECODE-ROWS -v "E:\environment\mysql-8.0.41-winx64\data\binlog.000046" > "E:\recovery_data1.sql"

import redef generate_recovery_sql(binlog_file_path, output_file_path):with open(binlog_file_path, 'r', encoding='utf-16') as f_in:binlog_content = f_in.read()# Regex to find DELETE statements and capture the SET_VAR lines that contain the column values# We look for '### DELETE FROM `mall_wxyoupin_com`.`yoshop_upload_file`' followed by '### WHERE' and then '### SET_VAR' linesdelete_pattern = re.compile(r'### DELETE FROM `mall_wxyoupin_com`\.`yoshop_upload_file`\n'r'### WHERE\n'r'(.*?)(?=\n### @|\n# at |$)',re.DOTALL)# Column mapping based on the table structure and @ variable indicescolumn_mapping = {1: 'file_id',2: 'group_id',3: 'channel',4: 'storage',5: 'domain',6: 'file_type',7: 'file_name',8: 'file_path',9: 'file_size',10: 'file_ext',11: 'cover',12: 'uploader_id',13: 'is_recycle',14: 'is_delete',15: 'store_id',16: 'create_time',17: 'update_time',}recovery_statements = []for match in delete_pattern.finditer(binlog_content):where_clause_block = match.group(1)# Extract all @ variables and their values from the WHERE clause blockset_var_matches = re.findall(r'###   @(\d+)=([\s\S]*?)(?=\n###   @|\n)', where_clause_block)row_values = {}for var_index_str, var_value_str in set_var_matches:var_index = int(var_index_str)# Clean up the value string: remove leading/trailing spaces and quotes if presentvar_value = var_value_str.strip()if var_value.startswith("''") and var_value.endswith("''"):var_value = var_value[1:-1] # Remove outer single quoteselif var_value.startswith("'") and var_value.endswith("'"):var_value = var_value[1:-1] # Remove outer single quotesrow_values[var_index] = var_value# Construct the INSERT statementcolumns = []values = []for i in range(1, len(column_mapping) + 1):if i in row_values:columns.append(f'`{column_mapping[i]}`')# Handle string values by quoting them, numeric values directlyif isinstance(row_values[i], str) and not row_values[i].isdigit():values.append(f"'{row_values[i].replace("'", "''")}'") # Escape single quotes within stringelse:values.append(str(row_values[i]))else:# If a column is not found in the DELETE statement, it might be NULL or have a default value.# For recovery, it's safer to explicitly set it to NULL or its default if known.# For simplicity, we'll assume all columns are present in the DELETE's WHERE clause for now.# If not, this part needs more sophisticated handling based on schema defaults.pass # This case should ideally not happen if all columns are in the WHERE clauseif columns and values:insert_statement = f"INSERT INTO `mall_wxyoupin_com`.`yoshop_upload_file` ({', '.join(columns)}) VALUES ({', '.join(values)});"recovery_statements.append(insert_statement)with open(output_file_path, 'w', encoding='utf-8') as f_out:for statement in recovery_statements:f_out.write(statement + '\\n')return len(recovery_statements)if __name__ == "__main__":binlog_file = 'd:/phpstudy_pro/WWW/yp/yoshop2.0/数据库修改记录/圈子/recovery_data1.sql'output_sql_file = 'd:/phpstudy_pro/WWW/yp/yoshop2.0/数据库修改记录/圈子/recovery_yoshop_upload_file.sql'print(f"Starting recovery SQL generation from {binlog_file}...")num_statements = generate_recovery_sql(binlog_file, output_sql_file)print(f"Generated {num_statements} INSERT statements into {output_sql_file}")print("Recovery SQL generation complete. Please review the generated SQL file before executing it.")

 



python d:/phpstudy_pro/WWW/yp/yoshop2.0/generate_recovery_sql.py 执行会得到 recovery_yoshop_upload_file.sql


http://www.jsqmd.com/news/30258/

相关文章:

  • 2025年新能源水冷电机壳铝合金浇铸机批发厂家权威推荐榜单:户外围墙配件铝合金浇铸机/厨具锅铝合金浇铸机/手套模具铝合金浇铸机源头厂家精选
  • 2025年耐高温的轴承制造商权威推荐榜单:轴承耐高温源头/高速耐高温轴承/耐高温高速轴承源头厂家精选
  • Chef:开源 AI 全栈应用构建工具实践
  • 2025年哈尔滨发动机维修保养权威推荐榜单:汽车维修/汽车保养/变速箱维修保养服务商精选
  • 2025 年 11 月阻燃石墨,膨胀石墨,导热石墨母粒厂家最新推荐,产能、专利、环保三维数据透视!
  • 2025 年 11 月石墨烯,可膨胀石墨,导热石墨母粒厂家最新推荐,产能、专利、环保三维数据透视!
  • [CSP-S 2025] 社团招新 / club题解
  • La Suite Docs:开源协作文档平台,可私有部署的 Notion 替代方案
  • Cisco Jabber 15.1 (Andriod, iOS, macOS, Windows) - 面向企业的多合一通信工具
  • Shotcut 25.10 (Linux, macOS, Windows) - 免费开源视频编辑器
  • Cisco Packet Tracer 9.0 新增功能简介
  • 划分型dp
  • 2025年青石栏杆制造厂权威推荐榜单:别墅石栏杆/石栏杆/河道石栏杆源头厂家精选
  • 2025年高分子聚乙烯衬板生产商权威推荐榜单:高分子聚乙烯耐磨板/聚乙烯耐磨衬板/超高分子聚乙烯衬板源头厂家精选
  • 2025年燃气发电机组制造商权威推荐榜单:石油管道发电机组/矿山用发电机组制造企业/加油站静音发电机设备源头厂家精选
  • 2025 年 11 月 DALI 控制器厂家推荐排行榜,DALI 控制器主机,DALI 照明控制系统,智能调光控制器公司精选
  • 【2025-11-02】连岳摘抄
  • 2025年手动叠片过滤器生产厂家权威推荐榜单:全自动反冲洗叠片过滤器/离心过滤器/钢制离心过滤器设备源头厂家精选
  • session cookie token它们三个的区
  • 弧焊机器人保护气智能节气装置
  • 2025年压管机厂家权威推荐榜单:缩管机/锁管机/扣管机/啤喉机源头厂家精选
  • 2025 年窗帘品牌最新推荐榜,聚焦品牌技术创新、产品品质与市场服务能力深度解析遮光 / 智能 / 蕾丝 / 百叶窗帘推荐
  • 纳尼?自建K8s集群日志收集还能通过JMQ保存到JES
  • 2025 年艺术漆品牌最新推荐榜,综合实力与核心竞争力全面剖析,兼具品质与服务的优质之选艺术漆一线品牌公司推荐
  • 20232313 2025-2026-1 《网络与系统攻防技术》实验四实验报告 - 20232313
  • 企业热线电话系统的多渠道支持与服务拓展策略!
  • 2025 年关节电机厂家最新推荐排行榜权威发布:揭秘行业优质品牌实力、口碑及选购要点无刷直流 / 力矩 / 机械臂 / 机械手关节电机公司推荐
  • 由于 CSP 烂完了于是加训
  • DockerDeskTop安装常用的中间件
  • 2025 年卷板机源头厂家最新推荐排行榜:涵盖不锈钢 / 大型 / 锥形 / 数控等多类型设备,助力企业精准采购优质产品