美文网首页
mysql恢复单库、单表

mysql恢复单库、单表

作者: 惩戒之箭 | 来源:发表于2017-04-18 22:27 被阅读31次

转: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文件中。

相关文章

网友评论

      本文标题: mysql恢复单库、单表

      本文链接:https://www.haomeiwen.com/subject/fmgqzttx.html