2.使用sed:与上面类似,假设你要恢复 table2 表,可以使用下面的语句:cat mydumpfile.sql | sed -n -e '/Table structure for table .test1./,/Table structure for table .test2./p' > /tmp/extracted_table.sql 备份:mysqldump -u root -ppasswd dbname tablename>table.sql;还原:mys...
mysqldump导出的表怎么还原
你好!
这个问题不是MYSQL数据库方面的问题,而是如何从一个文本文件中取出需要的部分内容的问题。 从数据库角度来说,没有什么好办法,可以使用操作系统中的文本编辑处理工具来实现。例如,如果不是太大,几百M可以用editplus,ultraedit等编辑工具打开找你需要sql拷贝出来导入。
如果是linux/unix,可参考如下方法:
1.使用 awk:
可以先到原数据库中使用 'show tables;' 查看数据库表的列表,注意,此列表已经按照字母排序,例如:
table1
table2
table3
然后使用awk 来过滤sql语句,假设你要恢复 table2 表,可以使用下面的语句:
awk ‘/^-- Table structure for table .table2./,/^-- Table structure for table .table3./{print}’ mydumpfile.sql > /tmp/recovered_table.sql
2.使用sed:
与上面类似,假设你要恢复 table2 表,可以使用下面的语句:
cat mydumpfile.sql | sed -n -e '/Table structure for table .test1./,/Table structure for table .test2./p' > /tmp/extracted_table.sql2016-07-25
备份:
mysqldump -u root -ppasswd dbname tablename>table.sql;
还原:
mysql -u root -ppasswd dbname < table.sql;2016-07-25