Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import single database from --all-databases dump

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.

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.

like image 556
savageguy Avatar asked Feb 26 '10 14:02

savageguy


1 Answers

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.

Another option which is IMHO much safer, is to extract the DB from an --all-databases dump. Example:

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.

(Credits goes to: Darren Mothersele - see his page)

like image 115
Hetzbh Avatar answered Sep 18 '22 16:09

Hetzbh