norman.lol
norman.lol

Reputation: 5374

What happens when you re-import an existing MySQL database?

Let's say I have created a MySQL database (in an encapsulated local development environment):

$ mysql -uroot -proot -e "create database FOO"

And imported an SQL dump:

$ mysql -uroot -proot FOO < /var/tmp/BAR.sql

And now I simply re-import a newer dump from the same source:

$ mysql -uroot -proot FOO < /var/tmp/FUBAR.sql

Questions: Is this a reliable method to simply import the newest data? Will existing tables simply be overwritten? As far as I can inspect it seems to be no problem. Or should I always better drop the database first, recreate it and then import the newer dump?

Upvotes: 2

Views: 1876

Answers (1)

Maadinsh
Maadinsh

Reputation: 435

Depends on the dump file. If it has DROP TABLE IF EXISTS and CREATE TABLE statements, it will overwrite tables. But it can also do any other thing SQL allows you to do - alter tables, only insert data, etc.

I see nothing unreliable in that.

Upvotes: 1

Related Questions