我有一个mysqldump备份我的mysql数据库,包括我们所有的表,这是大约440兆。我只想从mysqldump中恢复其中一个表的内容。这可能吗?从理论上讲,我可以只删除重建我想要的表的部分,但我甚至不知道如何有效地编辑这种大小的文本文档。
当前回答
备份 mysqldump-A.gz - | gzip > 恢复单表 $ mysql -e "truncate TABLE_NAME $ zgrep ^"INSERT INTO \ ' TABLE_NAME" mysqldump-A.gz | mysql DB_NAME
其他回答
我使用了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列表)。
一个简单的解决方案是仅为希望单独恢复的表创建一个转储。你可以使用mysqldump命令来这样做,语法如下:
mysqldump -u [user] -p[password] [database] [table] > [output_file_name].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.
您可以使用如下所示的终端线导入单个表。 这里导入单个用户表到特定的数据库。
mysql -u root -p -D my_database_name < var/www/html/myproject/tbl_user.sql
推荐文章
- 如何通过查询在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特权来执行此操作
- 从存储引擎得到错误28