简体   繁体   English

Mysqldump:将单个备份表还原到原始数据库

[英]Mysqldump: Restore a single backuped table to the original DB

I am trying to backup a specific table using mysqldump.我正在尝试使用 mysqldump 备份特定表。 I do so with this batch commandline:我用这个批处理命令行这样做:

mysqldump.exe --host=<IP> --user=<USER> --password=<PASSWORD> --port=<PORT> <DB_NAME> <TABLE_NAME> > backup.sql

What I receive in the resulted file are such commands:我在结果文件中收到的是这样的命令:

DROP TABLE IF EXISTS `<TABLE_NAME>`;
CREATE TABLE `<TABLE_NAME>` (...)

The problem is, in this scenario the table will be created in the default DB and not necessarily in the one I intended.问题是,在这种情况下,表将在默认数据库中创建,而不必在我想要的数据库中创建。 I would like to have something like this:我想要这样的东西:

USE <DB_NAME>;
DROP TABLE IF EXISTS `<TABLE_NAME>`;
CREATE TABLE `<TABLE_NAME>` (...)

How could I create that using Mysqldump?我如何使用 Mysqldump 创建它?

You don't need this.你不需要这个。 When you restore the dump you use mysql (not mysqldump) and therefor you give the database as argument like you did when using the dump.当您恢复转储时,您使用 mysql(不是 mysqldump),因此您可以像使用转储时一样将数据库作为参数。

mysql -uuser -ppassword -hhost databsename < yourdumpfilename mysql -uuser -ppassword -hhost 数据库名 < yourdumpfilename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM