我不小心清空了一个表。我有备份,但备份是整个数据库,大约 10GB。如何只从备份中还原一个表?可能吗?
来自 http://blog.tsheets.com/2008/tips-tricks/mysql-restoring-a-single-table-from-a-huge-mysqldump-file.html
$ awk '/Table structure for table .test1./,/Table structure for table .test2./{print}' mydumpfile.sql > /tmp/extracted_table.sql
您只需从备份 SQL 中提取一个表。
您可以使用 sed 执行此操作,例如
sed -n -e '/CREATE TABLE `mytable`/,/CREATE TABLE/p' backup.sql > mytable.sql
(只要它不是转储中的最后一个表,这就可以工作(我认为)。输出文件将包含一个额外的行,一个部分的 CREATE TABLE 语句。