我有一个mysqldump备份我的mysql数据库,包括我们所有的表,这是大约440兆。我只想从mysqldump中恢复其中一个表的内容。这可能吗?从理论上讲,我可以只删除重建我想要的表的部分,但我甚至不知道如何有效地编辑这种大小的文本文档。
当前回答
这能更容易做到吗?我是这样做的:
创建一个临时数据库(例如restore):
Mysqladmin -u root -p create restore
恢复临时数据库中的完整转储:
Mysql -u root -p——one-database restore < fulldump.sql
转储需要恢复的表:
Mysqldump恢复mytable
在另一个数据库中导入表:
Mysql -u root -p database < mytable.sql
其他回答
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.
这能更容易做到吗?我是这样做的:
创建一个临时数据库(例如restore):
Mysqladmin -u root -p create restore
恢复临时数据库中的完整转储:
Mysql -u root -p——one-database restore < fulldump.sql
转储需要恢复的表:
Mysqldump恢复mytable
在另一个数据库中导入表:
Mysql -u root -p database < mytable.sql
大多数现代文本编辑器应该能够处理这样大小的文本文件,如果您的系统能够胜任的话。
不管怎样,有一次我不得不很快地做这件事,而我没有时间去找任何工具。我设置了一个新的MySQL实例,导入了整个备份,然后输出了我想要的表。
然后我将该表导入主数据库。
这很乏味,但相当容易。祝你好运。
一种可能的处理方法是恢复到临时数据库,并从临时数据库中转储该表。然后使用新的脚本。
sed -n -e '/-- Table structure for table `my_table_name`/,/UNLOCK TABLES/p' database_file.sql > table_file.sql
这是一种比上面其他解决方案更好的解决方案,因为并非所有SQL转储都包含DROP TABLE语句。这将工作将所有类型的转储。
推荐文章
- 在MySQL中检测值是否为number
- MySQL中两个日期之间的差异
- 为什么在MySQL中文本列不能有一个默认值?
- 使用SQL查询查找最近的纬度/经度
- 如何停止mysqld
- 检查MySQL表是否存在而不使用“select from”语法?
- 从NOW() -1天选择记录
- 从表中选择1是什么意思?
- 数据库性能调优有哪些资源?
- 如何更改表的默认排序规则?
- MySQL foreign_key_checks是否影响整个数据库?
- 设置NOW()为datetime数据类型的默认值?
- 在MySQL中Datetime等于或大于今天
- 删除MySQL中的主键
- 我如何在MySQL中添加更多的成员到我的enum类型列?