MySQL 从 --all-databases 转储导入单个数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2342356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import single database from --all-databases dump
提问by savageguy
Is it possible to import a single database from an --all-databases mysqldump? I guess I can modify the file manually but wondering if there are any command line options to do this.
是否可以从 --all-databases mysqldump 导入单个数据库?我想我可以手动修改文件,但想知道是否有任何命令行选项可以做到这一点。
I am moving servers and have a lot of databases, most of which I don't currently need or want at the moment but would like to have the option to restore a single one if need be.
我正在移动服务器并且有很多数据库,其中大部分我目前不需要或不想要,但如果需要,我希望可以选择恢复单个数据库。
回答by Hetzbh
You can use the following command:
您可以使用以下命令:
mysql -u root -p --one-database destdbname < alldatabases.sql
Where destdbname
is your desired database which you want to restore.
destdbname
您想要恢复的所需数据库在哪里。
Another option which is IMHO much safer, is to extract the DB from an --all-databases
dump. Example:
恕我直言,另一个更安全的选择是从--all-databases
转储中提取数据库。例子:
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' alldatabases.sql > output.sql
Replace dbname
with the desired database name. alldatabases.sql
is the name of your sql-dump file. That way you'll have the seperated DB on file, and then you can restore using a simple mysql command.
替换dbname
为所需的数据库名称。alldatabases.sql
是您的 sql-dump 文件的名称。这样,您将拥有单独的数据库文件,然后您可以使用简单的 mysql 命令进行恢复。
Good luck
祝你好运
(Credits goes to: Darren Mothersele - see his page)
(致谢:Darren Mothersele - 见他的页面)
回答by Quassnoi
mysqldump
output is just a set of SQL
statements.
mysqldump
输出只是一组SQL
语句。
You can provide the desired database in the command line and skip the commands against the other databases using:
您可以在命令行中提供所需的数据库,并使用以下命令跳过针对其他数据库的命令:
mysql -D mydatabase -o mydatabase < dump.sql
This will only execute the commands when mydatabase
is in use
这只会mydatabase
在使用时执行命令