Mysql – Lost connection to thesql while restoring dump. Is it safe to resume

MySQLmysqldumprestore

I was in the process of restoring an sql dump to a newly created RDS mysql instance on AWS.

The dump was created with the following command:

mysqldump 
--all-databases \
--single-transaction \
--compress \
--order-by-primary > dump.sql

During the restore process I lost connection to the RDS instance.

Can I simply restart the restore process of the dump by re-initiating the restore process?

Or, asking more generally:

What excactly happens when restoring an sql dump?
Will already created tables simply be overwritten? Will the database delete old entries and copy over the new database state?

Best Answer

(n.b. I've never used AWS or RDS so there may be some differences). But as a general rule a MySQL DUMP file is just a series of CREATE TABLE and INSERT INTO statements, that when combined create your database.

Ultimately it depends on what options were chosen as to what does and doesn't get included. But I think that by default it includes the --add-drop-table option. So if you open the file (which is basically a text file) you should see:

DROP TABLE tablename;
CREATE TABLE tablename. . .
INSERT INTO tablename. . . 

for all of your tables.

Restarting the loading process will simply start from the beginning of the file and carry out the actions accordingly.

(I assume that the import has actually died - its not uncommon (in my experience) to lose connection to MySQL during the import due to the time taken, but the process continues in the background. You can use SHOW PROCESSLIST to check this).