简体   繁体   中英

Mysqldump: Restore a single backuped table to the original DB

I am trying to backup a specific table using 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?

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 -uuser -ppassword -hhost databsename < yourdumpfilename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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