views:

20

answers:

2

If I have exported a .sql file with my database in it, can I then only import "parts" of that database instead of the entire database to MySql?

The question appeared when I was trying it out on a test database.

I exported the testdatabase.

Then emptied some of the tables in the database.

Then I planned on importing from the .sql file and hope the emptied tables would be refilled with whatever they where populated with.

But I get an error:

#1007 Can't create database 'database_name' - database exists

Offcourse it exists, but is it possible to only import values of the already existing tables from the .sql backup?

Or must I remove the entire database and then import the database?

FYI I am using PhpMyAdmin for this currently.

+1  A: 

It's straightforward to edit the file and remove the parts you're not interested in having restored, Camran.

Alternatively - import the entire file into a separate database (change the database name @ the top of the file) and then use INSERT statements to copy the data from the tables in this new database to the other.

Will A
I am after a simpler way than editing the whole sql file!
Camran
Edited to provide a suitable alternative approach.
Will A
A: 

I solved this problem by writing a script to dump each table into each individual file and all the CREATE TABLE statements off in their own file. It's gotten a bit long and fancy over the years, so I can't really post it here.

The other approach is to tell MySQL to ignore errors. With the CLI, you provide the -f switch, but I'm not familiar enough with PhpMyAdmin to know how to do that.

staticsan