{"id":19528944,"url":"https://github.com/lianjiatech/lightning","last_synced_at":"2025-10-29T09:23:12.851Z","repository":{"id":57531500,"uuid":"219950149","full_name":"LianjiaTech/lightning","owner":"LianjiaTech","description":"lightning is a tool for binlog parsing. It can generate original SQL or flashback SQL.","archived":false,"fork":false,"pushed_at":"2024-07-26T08:48:43.000Z","size":3600,"stargazers_count":74,"open_issues_count":6,"forks_count":25,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-01-21T15:08:21.042Z","etag":null,"topics":["binlog","flashback","mysql","rollback"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LianjiaTech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-06T08:41:40.000Z","updated_at":"2024-07-26T08:48:46.000Z","dependencies_parsed_at":"2024-06-20T03:17:28.226Z","dependency_job_id":"029266f1-cf84-47a2-8cc5-cc67915bc3d5","html_url":"https://github.com/LianjiaTech/lightning","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LianjiaTech%2Flightning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LianjiaTech%2Flightning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LianjiaTech%2Flightning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LianjiaTech%2Flightning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LianjiaTech","download_url":"https://codeload.github.com/LianjiaTech/lightning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236176766,"owners_count":19107393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binlog","flashback","mysql","rollback"],"created_at":"2024-11-11T01:21:00.845Z","updated_at":"2025-10-29T09:23:12.779Z","avatar_url":"https://github.com/LianjiaTech.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 简介\n\n[文档](http://github.com/LianjiaTech/lightning/blob/master/doc/) | [English Readme](http://github.com/LianjiaTech/lightning/blob/master/README_EN.md)\n\n![lightning](https://github.githubassets.com/images/icons/emoji/unicode/26a1.png) lightning 是由贝壳找房 DBA 团队开发和维护的一个 MySQL binlog 转换工具。该工具可以将 MySQL ROW 格式的 binlog 转换为想要的 SQL，如：原始 SQL，闪回 SQL等。也可以对 binlog 进行统计分析，用于数据库异常分析。甚至可以通过定制 lua 插件进行二次开发，发挥无限的想象力。\n\n## 应用\n\n* 数据修改错误，需要快速回滚 (闪回)\n  * DELETE, UPDATE 未指定 WHERE 条件\n  * UPDATE SET 误用 AND 连接\n* 数据异常， 从 binlog 中找特定表某些数据是什么时间修的\n* 业务流量异常或从库同步延迟，需要统计排查是哪些表在频繁更新\n* 需要把指定表，指定时间的更新提供给开发定位服务异常问题\n* 主从切换后新主库丢失数据的修复\n* 从 binlog 生成标准 SQL，带来的衍生功能\n* 找出某个时间点数据库是否有大事务 (Size) 或者长事务 (Time)\n\n## 优点\n\n* 跨平台支持，二进制文件即下即用，无其他依赖。\n* 支持 lua 定制化插件，发挥无限的想象力，二次开发周期短。\n* 支持从 SQL 文件加载库表信息，不必连接 MySQL 便于历史变更恢复。\n* SQL 进行多行合并，相比 mysqlbinlog ROW 格式，更好过滤。\n\n## 安装\n\n### 二进制安装\n\nlightning 使用 Go 1.11+ 开发，可以直接下载编译好的二进制文件在命令行下使用。由于 Go 原生对跨平台支持较好，在 Windows, Linux, Mac 下均可使用。\n\n[下载地址](https://github.com/LianjiaTech/lightning/releases)\n\n### 源码安装\n\n```bash\ngo get -d github.com/LianjiaTech/lightning\ncd ${PATH_TO_SOURCE}/lightning # 进入源码路径，PATH_TO_SOURCE 需要人为具体指定。\nmake\n```\n\n## 测试示例\n\n[常用命令](http://github.com/LianjiaTech/lightning/blob/master/doc/cmd.md)\n\n直接读取文件生成回滚语句\n\n```bash\nlightning -no-defaults \\\n-plugin flashback \\\n-start-datetime \"2019-01-01 00:00:00\" \\\n-stop-datetime \"2019-01-01 00:01:00\" \\\n-event-types delete,update \\\n-tables test.tb \\\n-schema-file schema.sql \\\n-binlog-file binlog.0000001 \u003e flashback.sql\n```\n\n使用 `Binlog Dump` 方式读取日志生成回滚语句\n\n```bash\ncat \u003e master.info\nmaster_host: 127.0.0.1\nmaster_user: root\nmaster_password: ****** \nmaster_port: 3306\nmaster_log_file: binlog.000002\nmaster_log_pos: 4\n\u003cctrl\u003e+D\n\nlightning -no-defaults \\\n-plugin flashback \\\n-start-datetime \"2019-01-01 00:00:00\" \\\n-stop-datetime \"2019-01-01 00:01:00\" \\\n-event-types delete,update \\\n-tables test.tb \\\n-master-info master.info \u003e flashback.sql\n```\n\n## 配置\n\nlightning 使用 YAML 格式的配置文件。使用 `-config` 参数指定配置文件路径，如不指定默认按 /etc/lightning.yaml -\u003e ./etc/lightning.yaml -\u003e ./lightning.yaml 的顺序加载配置文件。如果不想使用默认路径下的配置文件还可以通过 `-no-defaults` 参数屏蔽所有默认配置文件。\n\n* [全局配置](http://github.com/LianjiaTech/lightning/blob/master/doc/global.md)\n* [MySQL 日志源](http://github.com/LianjiaTech/lightning/blob/master/doc/mysql.md)\n* [过滤器](http://github.com/LianjiaTech/lightning/blob/master/doc/filters.md)\n* [SQL 重建规则](http://github.com/LianjiaTech/lightning/blob/master/doc/rebuild.md)\n\n## 限制/局限\n\n* 仅测试了 v4 版本 (MySQL 5.1+) 的 binlog，更早版本未做测试。\n* BINLOG_FORMAT = ROW\n* 参数 BINLOG_ROW_IMAGE 必须为 FULL，暂不支持 MINIMAL\n* 由于添加了更多的处理逻辑，解析速度不如 mysqlbinlog 快\n* 当 binlog 中的 DDL 语句变更表结构时，lightning 中的表结构原数据并不随之改变（TODO）\n\n## 沟通交流\n\n* [常见问题(FAQ)](http://github.com/LianjiaTech/lightning/blob/master/doc/FAQ.md)\n* 欢迎通过 Github Issues 提交问题报告与建议\n* QQ 群： 573877257\n\n![QQ](https://github.com/LianjiaTech/lightning/raw/master/doc/qq_group.png)\n\n## License\n\n[Apache License 2.0](http://github.com/LianjiaTech/lightning/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flianjiatech%2Flightning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flianjiatech%2Flightning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flianjiatech%2Flightning/lists"}