phpmysqlsqlsecuritymysql-error-1007

Only import tables from a complete MySql database export


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.


Solution

  • 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.