操作巨大的 MySQL 转储文件
获取单个表的数据、删除单个表或将整个转储文件分解为每个包含单独表的文件的最简单方法是什么? 我通常最终会进行大量的 vi 正则表达式修改,但我打赌有更简单的方法可以使用 awk/perl 等来完成这些事情。Google 结果的第一页带回了一堆无法工作的 perl 脚本。
What's the easiest way to get the data for a single table, delete a single table or break up the whole dump file into files each containing individual tables? I usually end up doing a lot of vi regex munging, but I bet there are easier ways to do these things with awk/perl, etc. The first page of Google results brings back a bunch of non-working perl scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此 shell 脚本将获取您想要的表并将它们传递给
splitted.sql
。它能够理解正则表达式,因为我添加了 sed -r 选项。
MyDumpSplitter 还可以将转储拆分为单独的表转储。
This shell script will grab the tables you want and pass them to
splitted.sql
.It’s capable of understanding regular expressions as I’ve added a
sed -r
option.Also MyDumpSplitter can split the dump into individual table dumps.
Maatkit 似乎非常适合 mk-parallel-dump 和 mk-parallel-restore.
Maatkit seems quite appropriate for this with mk-parallel-dump and mk-parallel-restore.
我在这方面有点晚了,但如果它可以帮助任何人,我必须拆分一个巨大的 SQL 转储文件才能将数据导入到另一个 Mysql 服务器。
我最终做的是使用系统命令拆分转储文件。
split -l 1000 import.sql splited_file
上面将每 1000 行分割 sql 文件。
希望这对某人有帮助
I am a bit late on that one, but if it can help anyone, I had to split a huge SQL dump file in order to import the data to another Mysql server.
what I ended up doing was splitting the dump file using the system command.
split -l 1000 import.sql splited_file
The above will split the sql file every 1000 lines.
Hope this helps someone
当我需要从 sql 转储中提取单个表时,我使用 grep、head 和 tail 的组合。
例如:
然后,这将为您提供每个表的行号,因此,如果您的表位于第 200 行,而后一个表位于第 269 行,我会这样做:
我想您可以扩展这些原则来构建一个可以拆分的脚本将整个事情分解为每个表一个文件。
有人想在这里尝试一下吗?
另一点可能有助于启动 bash 循环:
这为您提供了一个很好的行号和表名称列表,例如:
When I need to pull a single table from an sql dump, I use a combination of grep, head and tail.
Eg:
This then gives you the line numbers for each one, so if your table is on line 200 and the one after is on line 269, I do:
I would imagine you could extend upon those principles to knock up a script that would split the whole thing down into one file per table.
Anyone want a go doing it here?
Another bit that might help start a bash loop going:
That gives you a nice list of line numbers and table names like:
如果可以的话,可以使用
mysqldump -T
,这样可以省去很多麻烦。来自 文档:
Save yourself a lot of hassle and use
mysqldump -T
if you can.From the documentation: