我有一个mysqldump备份我的mysql数据库,包括我们所有的表,这是大约440兆。我只想从mysqldump中恢复其中一个表的内容。这可能吗?从理论上讲,我可以只删除重建我想要的表的部分,但我甚至不知道如何有效地编辑这种大小的文本文档。
当前回答
您可以使用vi编辑器。类型:
vi -o mysql.dump mytable.dump
打开全部转储mysql。Dump和一个新文件mytable.dump。 通过按/找到合适的insert into line,然后键入一个短语,例如:"insert into ' mytable ' ",然后使用yy复制这一行。按ctrl+w然后向下方向键切换到下一个文件,用pp粘贴复制的行。最后输入:wq保存新文件,用:q保存。
注意,如果您使用多个插入转储了数据,您可以使用Nyy一次复制(yank)所有数据,其中N是要复制的行数。
我用一个920 MB大小的文件做了这件事。
其他回答
表应该在转储和数据库中呈现相同的结构。
`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql.tar.gz | mysql -u<user> -p<password> database_name`
or
`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql | mysql -u<user> -p<password> database_name`
我使用了uloBasEI的sed命令的修改版本。它包括前面的DROP命令,读取直到mysql完成转储数据到你的表(解锁)。为我工作(重新)导入wp_users到一堆Wordpress网站。
sed -n -e '/DROP TABLE.*`mytable`/,/UNLOCK TABLES/p' mydump.sql > tabledump.sql
这个工具可能就是你想要的:tbdba-restore-mysqldump.pl
https://github.com/orczhou/dba-tool/blob/master/tbdba-restore-mysqldump.pl
从数据库转储文件中恢复一个表:
Tbdba-restore-mysqldump.pl -t yourtable -s yourdb -f backup.sql
我尝试了一些选择,它们都非常慢。这将在几分钟内将一个360GB的转储拆分到它的表中:
如何将mysqldump的输出分割成更小的文件?
Get a decent text editor like Notepad++ or Vim (if you're already proficient with it). Search for the table name and you should be able to highlight just the CREATE, ALTER, and INSERT commands for that table. It may be easier to navigate with your keyboard rather than a mouse. And I would make sure you're on a machine with plenty or RAM so that it will not have a problem loading the entire file at once. Once you've highlighted and copied the rows you need, it would be a good idea to back up just the copied part into it's own backup file and then import it into MySQL.
推荐文章
- 将表从一个数据库复制到另一个数据库的最简单方法?
- 如何通过查询在MySQL中获得数据库结构?
- MySQL删除表中的所有行,并将ID重置为零
- 在准备语句中使用“like”通配符
- MySQL中的表名是否区分大小写?
- 库未加载:libmysqlclient.16。在OS X 10.6上使用mysql2 gem运行'rails server'时出现dylib错误
- 如何知道MySQL表最近一次更新?
- 在MySQL中的一个查询中更新多个具有不同值的行
- 如果表存在则删除表并创建它,如果不存在则创建它
- MySQL OR与IN性能
- 将值从同一表中的一列复制到另一列
- 删除id与其他表不匹配的sql行
- MySQL CPU使用率高
- INT和VARCHAR主键之间有真正的性能差异吗?
- 拒绝访问;您需要(至少一个)SUPER特权来执行此操作