惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
V2EX - 技术
V2EX - 技术
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
S
Schneier on Security
I
InfoQ
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The GitHub Blog
The GitHub Blog
S
Security @ Cisco Blogs
O
OpenAI News
W
WeLiveSecurity
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
人人都是产品经理
人人都是产品经理
Cloudbric
Cloudbric
The Last Watchdog
The Last Watchdog
The Hacker News
The Hacker News
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
NISL@THU
NISL@THU
T
Tailwind CSS Blog
V
Visual Studio Blog
PCI Perspectives
PCI Perspectives
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
D
DataBreaches.Net
B
Blog RSS Feed
N
News and Events Feed by Topic
N
News and Events Feed by Topic
H
Heimdal Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
腾讯CDC
Latest news
Latest news
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
V
V2EX
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
Help Net Security
Help Net Security

博客园 - 步孤天

程序员去新加坡打工的杂事记录 基于Bert的中文评价情感分析 (转载)DeepSeek+LoRA+FastAPI-微调大模型并暴露接口给后端调用 用YOLOv5截取出短剧的人物 Chromium源码分析五:写一个利用ipc+protobuf通信的demo Chromium源码分析四:RunLoop、Bind、scoped_refptr Chromium源码分析三:Chromium中用到的设计模式 Chromium源码分析二:LifeofaPixel.pdf Chromium源码分析一:基础知识 交叉编译valgrind在嵌入式设备上调试程序 gerrit 反向代理从 apache 换成 nginx 之后项目页报错“The page you requested was not found, or you do not have permission to view this page” golang实现一个简单的文件浏览下载功能代码示例 六十花甲子纳音表中的五行是怎么算出来的 df查看30GB的磁盘满了而du -sh查看磁盘占用只有6GB centos7+mariadb安装在线评判系统 如何去掉Linux vim文本中的^M golang如何打印变量类型,golang list如何把元素转换为可用类型 数据库文件导入报错"MySQL server has gone away" 如何在Linux上用tshark命令把抓包中follow的二进制流保存成文件
如何从超大(10G)sql语句文本中分离出需要的部分
步孤天 · 2023-04-13 · via 博客园 - 步孤天

背景

项目在运营过程中,经常会将mysql全量备份。备份的文本有10多GB。
当需要用一部分数据来重现某个项目问题时就犯难了:

  1. 10多GB导入到mysql没必要且耗时;
  2. 复制一份数据用vim将不用的部分删掉,vim打开查找的速度太慢了;

解决办法

  1. 找到所有数据库所在的行号;
grep "CREATE DATABASE " ali_mysql_202301.sql -n  >> dbname.log
  1. 从dbname.log中找到所需数据库的行号和下一个数据库的行号
5587:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `v01_zs` /*!40100 DEFAULT CHARACTER SET utf8 */;
6712:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `v02_ls` /*!40100 DEFAULT CHARACTER SET utf8 */;
7632:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `v03_ww` /*!40100 DEFAULT CHARACTER SET utf8 */;
9370:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `v04_zl` /*!40100 DEFAULT CHARACTER SET utf8 */;

比如我们要取v02_ls,那么就从ali_mysql_202301.sql导出6712-7632行就行了。可以使用python脚本来实现getsql.py

name = 'v02_ls.sql'
srcname = 'ali_mysql_202301.sql'
cnt = 0
file = open(srcname)
with open(name, 'a+') as f:
    for line in file:
        if cnt > 6712 and cnt < 7632 :
            f.write(line)
        cnt = cnt + 1
file.close()
f.close()

将行号填写到cnt > 6712 and cnt < 7632这行然后执行脚本

python getsql.py

就可以得到想要的数据了(v02_ls.sql)