MariaDB taking ages to restore backup

Solution 1:

It sounds as the underlying disks are busy. The problem in restoring a large database is that each (group of) INSERT requires a flush/sync operation, which is very slow on mechanical disks (a 7200 RPM disk is in the order of ~100 IOPS).

To hasten the restore, you had to temporarily instruct MySQL/MariaDB to not issue flushes/syncs. To do that, interrupt the restore and edit your /etc/my.ini with the following two lines:

  • innodb_flush_method=nosync
  • innodb_flush_log_at_trx_commit=2

Then restart MariaDB and retry the restore. Things should go much faster now.

After the restore, REMOVE THE ABOVE LINES or your database will have a short and bad life: flushes/syncs exists for very important reasons. While it is acceptable to turn them off for a restore, a production database should never run without them.

Solution 2:

If your underlying storage is plain old disks, for a 25GB-on-disk MySQL database, that's quite normal to experience hours-long restore - especially for some badly structured dbs (lots of tuples, indexes, etc.).

For a start compress your dump, that saves tons of I/Os and puts less stress on cache memory :

mysqldump foo |gzip >foo.sql.gz
zcat foo.sql.gz |mysql foo

In your case, since you already did the mysqldump :

gzip db_test.sql
zcat db_test.sql.gz |mysql db_test

Besides your system performance (storage, RAM, etc.), MySQL settings might have a huge impact. But that's a whole expertise there, nothing than can be handled thru a ServerFault issue...