mysql恢复单库、单表

转:http://lee90.blog.51cto.com/10414478/1836656

从全备份中,还原某一个库(假如要还原的库叫做hellodb)内容:

# mysqldump -uroot -proot --all-databases --master-data=2 > all.sql

# mysql -uroot -proot -e 'create database hellodb;'  还原之前,首先要确保这个库的已经存在了,不然下面的命令会提示失败】

# mysql -uroot -proot hellodb --one-database < all.sql   # --one-database 可以简写成-o

从全备份中恢复出某一个库里的一张表(以取出hellodb.students为例):

# sed -e'/./{H;$!d;}' -e 'x;/CREATE TABLE `students`/!d;q' all.sql 可以取出这张表的结构语句

# grep 'INSERT INTO `students`' all.sql  可取出students表中的内容

#grep 'INSERT INTO `students`' all.sql>students.sql  将结果保存到 students.sql文件中。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容