恢复mysql数据库时如何跳过表?
我有一个名为forum.sql 的大型mySQL 数据库转储。我只想恢复一张表,但是当我恢复整个数据库时,导入“post”表需要很长时间。
是否有任何选项可以跳过“post”表来恢复此数据库?
I have a big mySQL database dump named forum.sql. I want to restore only one table, but when I restore the full database, it takes a long time to import the "post" table.
Is there any option to restore this database skipping the "post" table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果要从转储文件恢复,则无需此表即可轻松构建新的转储文件,只需记下行号即可。
初始行
总行数
创建一个新文件
20 来自减去 63 - 43
不干净,但有用
If you are restoring from a dump file, you can easily build a new dumpfile without this table, just by writting down the line numbers.
Initial line
Total lines
Make a new file
20 comes from substracting 63 - 43
not clean, but usefull
或者,使用
sed
从fulldump.sql
中提取需要恢复的表:...etc
现在从
temp.sql
恢复>。Alternatively, extract the table(s) that need to be restored from
fulldump.sql
usingsed
:...etc
Now restore from
temp.sql
.恢复单个表
首先,使用零插入进行恢复:
此处使用 grep -v 将排除与该模式匹配的任何语句。本例中的模式使用
^
来匹配行的开头。结果应该是具有零数据的恢复模式。接下来,仅恢复所需的
INSERT
语句:这将仅恢复名为
的表的数据。请注意三个反斜杠。您需要一个反斜杠来转义反斜杠,然后您需要用另外 2 个反斜杠来转义反斜杠。
恢复除一个表之外的所有内容
当我想要恢复整个数据库但排除一两个表中的数据时,我一直使用的另一种技术是...您可以通过以下方式过滤掉任何不需要的
INSERT
语句:在将转储推入数据库之前,将其通过过滤器。以下是使用grep
作为过滤器的示例:即使您注销了 shell,
nohup
命令也会使sh
命令保持运行。如果您有一个需要相当长的时间才能恢复的大型转储文件,这会非常方便。grep
的-v
标志将排除与该模式匹配的任何内容。末尾的
&
会将命令发送到后台。Restore a single table
First, do the restore with zero inserts:
Using
grep -v
here will exclude any statements matching the pattern. The pattern in this case uses^
to match at the beginning of a line. The result should be a restored schema with zero data.Next, restore only your desired
INSERT
statements:That will restore data only for the table named
<table>
. Note the triple backslashes. You need a backslash to escape a backtick and then you need to escape the backslash with 2 more backslashes.Restore everything except one table
Another technique I use all the time when I want to restore an entire database but exclude the data from a table or two is this... You can filter out any unwanted
INSERT
statements by passing your dump through a filter before pushing into the db. Here's an example usinggrep
as the filter:The
nohup
command will keep thesh
command running even if you log out of your shell. That can be pretty handy if you have a large dump file that will take quite some time to restore.The
-v
flag forgrep
will exclude anything matching the pattern.The
&
at the end will send the command to the background.据我所知,没有。
您必须从转储文件中手动编辑不需要的表的
CREATE
和INSERT
语句。As far as I know, no.
You would have to manually edit the
CREATE
andINSERT
statements of the undesired table out of the dump file.我认为你做不到。但必要时您可以使用
--tables
myqsldump 选项单独转储表。因此,您可以为post
表生成一个转储,并为其余表生成另一个转储。例子:
I don't think you can do it. But you can dump tables separately when necessary, using
--tables
myqsldump option. So, you can generate a dump forpost
table and another dump for the remaining tables.Example:
您可以更改转储语句以使其使用忽略表吗? http://dev.mysql.com/doc/refman /5.1/en/mysqldump.html#option_mysqldump_ignore-table
You could alter your dump statement so that it uses ignore table? http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_ignore-table