我有一个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
其他回答
这个工具可能就是你想要的: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
我使用了uloBasEI的sed命令的修改版本。它包括前面的DROP命令,读取直到mysql完成转储数据到你的表(解锁)。为我工作(重新)导入wp_users到一堆Wordpress网站。
sed -n -e '/DROP TABLE.*`mytable`/,/UNLOCK TABLES/p' mydump.sql > tabledump.sql
您可以尝试使用sed,以便只提取所需的表。
假设你的表名为mytable,文件名为mysql。Dump是包含你的巨大转储的文件:
$ sed -n -e '/CREATE TABLE.*`mytable`/,/Table structure for table/p' mysql.dump > mytable.dump
这将复制到文件mytable中。dump位于CREATE TABLE mytable和对应下一个表的下一个CREATE TABLE之间的内容。
然后可以调整文件mytable。其中包含表mytable的结构和数据(一个INSERT列表)。
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.
我尝试了一些选择,它们都非常慢。这将在几分钟内将一个360GB的转储拆分到它的表中:
如何将mysqldump的输出分割成更小的文件?
推荐文章
- SQL Server恢复错误-拒绝访问
- 警告用户/local/mysql/data目录不属于mysql用户
- 添加一个复合主键
- 无法添加或更新子行:外键约束失败
- 如何从本地机器mysqldump远程数据库
- 如何正确地创建复合主键- MYSQL
- 仅在Datetime列上按日期分组
- 在MySQL数据库中存储货币值的最佳数据类型
- 如何自定义'显示进程列表'在mysql?
- MySQL删除一些外键
- 用MySQL LEFT JOIN删除行
- MySQL - length() vs char_length()
- 使用PDO进行行计数
- 在Mac上安装MySQL后,使用ALTER USER语句重置MySQL root密码
- my.cnf文件在macOS上的位置