简体   繁体   中英

mysqldump without adding USE database_name

I am looking for an option/idea how could I get rid of the statement 'USE database_name' when using mysqldump ? I manage to get rid of creating DB only.

Thank you!

I am not sure if there is an actual option for the mysqldump command but you could always just run the output through a filter like sed . For example:

mysqldump | sed -e '/^CREATE DATABASE/d' -e '/^USE `/d' >dumpFile.txt

Or if you have the dump file you would do it as:

sed -e '/^CREATE DATABASE/d' -e '/^USE `/d' <dumpFile.txt >cleanedUpDumpFile.txt

The second way might be better. If there is not too much data you can do:

diff dumpFile.txt cleanedUpDumpFile.txt | less

To verify that only the lines you wanted were deleted. If everything looks OK you can go with the first way to just generate what you want.

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