0

I currently have a MySQL dump of about 2GBs in size that consists of 10 databases. I need to skip few databases when I restore this dump. I couldn't find a solution on the internet or in Stackoverflow to ignore specific databases upon restoring a dump.

The command I use to restore on Ubuntu is:

$ mysql -u root -p < dump.sql

This command works fine but it restores all DBs. Is there a way to ignore one or many databases using an option like "--ignore-database" while doing this? Ex: DB to ignore "abc_db".

Teshan N.
  • 2,307
  • 3
  • 30
  • 59
  • Does this answer your question? [Skip certain tables with mysqldump](https://stackoverflow.com/questions/425158/skip-certain-tables-with-mysqldump) – Hirumina Jun 30 '20 at 05:33
  • See https://stackoverflow.com/questions/2342356/import-single-database-from-all-databases-dump – pifor Jun 30 '20 at 05:34
  • Does this answer your question? [Import single database from --all-databases dump](https://stackoverflow.com/questions/2342356/import-single-database-from-all-databases-dump) – pifor Jun 30 '20 at 05:40

1 Answers1

1

Ignore statements except those that occur while the default database is the one named on the command line. This option is rudimentary and should be used with care. Statement filtering is based only on USE statements.

mysql -u someone -p somedatabase < all.sql 

What you want to do is feed your sql dump directly to the mysql client with a command like this one:

bash > mysql -D your_database < your_sql_dump.sql

If you have access to the server where the dump comes from, then you could create a new dump with mysqldump --ignore-table=database.table_you_dont_want1 --ignore-table=database.table_you_dont_want2 ....

where somedatabase is the name of the database you want to extract and someone is mysql user .

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
  • So the "-D dbname" means the DB that needs to be ignored from the dump right? For that we need to create a db with that name on our server right? – Teshan N. Jun 30 '20 at 06:07