从mysqldump的备份文件中恢复一张表
2013-07-08 15:42
197 查看
有时需从mysqldump备份文件恢复一张表的数据,通常有两种做法:
1):将整个文件导入测试server中,再mysqldump导出需要的表,再导入线上server。
如果库的量很少,这样倒是也不慢,可当库的量有一定的级别了,就会很慢。很可能备份时使用了压缩,再需要解压缩的步骤。
2):通过mysql>show tables;查看到mysqldump备份时的表的备份顺序,其和show tables的看的顺序一样的。锁定了表的位置,通过awk或sed取出其需要的表数据。
针对方法2:
假如你show tables的结果为:
table_1
table_2
table_3
.......
table_n
此时想恢复table_10的数据时,使用awk做如下操作:
使用sed作如下操作:
其实方法2就是要知道,show tables的表顺序和mysqldump时的顺序相同;其次是dump出的文件特殊标志-- Table structure for table `table_n` 。
1):将整个文件导入测试server中,再mysqldump导出需要的表,再导入线上server。
如果库的量很少,这样倒是也不慢,可当库的量有一定的级别了,就会很慢。很可能备份时使用了压缩,再需要解压缩的步骤。
2):通过mysql>show tables;查看到mysqldump备份时的表的备份顺序,其和show tables的看的顺序一样的。锁定了表的位置,通过awk或sed取出其需要的表数据。
针对方法2:
假如你show tables的结果为:
table_1
table_2
table_3
.......
table_n
此时想恢复table_10的数据时,使用awk做如下操作:
zcat mysqldump.date.sql.gz|awk '/^-- Table structure for table `table_10`/,/^-- Table structure for table `table_11`/{print}' >/tmp/table_10.sql注意:awk的''和""的区别,假如""中使用``就会报错;其中``可以替换为..。如下
zcat mysqldump.date.sql.gz|awk "/^-- Table structure for table .table_10./,/^-- Table structure for table .table_11./{print}">/tmp/table_10.sql
使用sed作如下操作:
zcat mysqldump.date.sql.gz |sed -n -e '/-- Table structure for table `table_10`/,/-- Table structure for table `table_11`/p' >/tmp/table_10.sql
其实方法2就是要知道,show tables的表顺序和mysqldump时的顺序相同;其次是dump出的文件特殊标志-- Table structure for table `table_n` 。
相关文章推荐
- 从xtraback 备份文件中 单独恢复一张 innodb 表
- 快速从mysqldump 文件中恢复一张表
- 快速从mysqldump文件中恢复一张表
- 快速从mysqldump文件中恢复一张表
- 从mysqldump备份数据库里面恢复一张表时遇到的问题
- Windows计划任务+批处理文件实现oracle数据库的定时备份与恢复
- RMAN备份与恢复—将数据文件或表空间还原到新位置
- RMAN备份与恢复系列之TEMP表空文件恢复
- MongoDB数据库的文件备份恢复以及文件导入导出
- MongoDB数据库的文件备份恢复以及文件导入导出
- rman恢复未备份的数据文件
- 使用mysqlhotcopy命令备份的文件如何恢复
- oracle rman 备份与恢复 临时表空间的文件问题解决 留痕
- linux/unix文件系统的备份和恢复
- mysqldump实现简单备份恢复
- mysqldump全备份及结合binlog日志恢复的全过程 (转)
- 备份控制文件之后,添加数据文件,数据文件无备份丢失后的恢复
- [Mysql数据库] 将MYSQLDUMP全库备份分为单库文件的方法(自己写的小工具)
- 系统数据文件备份与恢复及只读数据文件备份与恢复
- virtualbox从.VDI备份文件新建/恢复虚拟机(包括恢复各个备份节点)