开发者

Only import tables from a complete MySql database export

开发者 https://www.devze.com 2023-01-13 08:21 出处:网络
If I have exported a .sql file with my database in it, can I then only import \"parts\" of that database instead of t开发者_C百科he entire database to MySql?

If I have exported a .sql file with my database in it, can I then only import "parts" of that database instead of t开发者_C百科he 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消