I've just bought a new home desktop. I have three MySQL databases that I want to move across. I dumped them all using mysqldump before removing the drive from the old machine.
Restoring the largest of the databases is taking ages (getting on for 24 hours so far). I'm restoring via:
mysql -uxxxx -p
Enter password: yyyy
mysql> create database foo;
mysql> use foo;
mysql> start transaction;
mysql> \. <dump-file>
I pray I remember to commit
when this finishes!
I abandoned my first attempt to restore, without the transaction as it was taking so long. I intend not to bother with the transaction when restoring the other two databases as it seems to make no difference.
Is there anything I can do to speed up the restore? Should I have done the backup differently - I just used a vanilla mysqldump
command line, with --skip-column-statistics
since the dump would otherwise fail, as proposed in this stackoverflow answer.
For reference, the new machine runs Windows 10 and MySQL 8.0.25 Community; the old machine ran Windows 7 and MySQL 5.6.22.
Looking at the dump files more closely (to find the server version), I see that the tables are created with their indexes, followed by a lot of INSERT INTO statements. This doesn't seem particularly clever. Is there a way to induce mysqldump
to produce a script that:
- Creates the tables without indexes
- Inserts the rows; and then
- Creates the indexes.
which would seem a better approach for when the database is being restored. (It's a little surprising that this isn't the default!) I assume this is possible with MySQL - I've been using SQLLite for the past 3 years and it's certainly possible there.
Update
This question isn't completely answered by How can I speed up a MySQL restore from a dump file?, since that question particularly refers to MyISAM tables, and mine are InnoDB. (Apologies. I probably should have mentioned the storage engine in my original question.)
That answer did, however motivate and inform my attempts to resolve matters, which I document in my own answer below.