I have a database MySQL
with the engine InnoDB
, which, some tables are very large (approximately 30GB each).
When making one Backup
or one Restore
of those tables from the Base de Datos
, I have the problem that it takes a long time to restore the copy using Dump
.
Is there any way to be able to perform the Backups
and Restores
of those tables very quickly?
NOTE:
This question is referenced from the next one, but with a different database storage engine.
InnoDB
Unlike other engines, it has an option to activate or deactivate the feature of having a file per table ( File-Per-Table ), which makes it easier for us to makeBackups
specificRestores
tables.To activate
File-Per-Table
you have to modify the configuration fileMySQL
and add the following in the label[mysqld]
:To activate the option, the MySQL service must be restarted once the configuration file has been modified.
To make a
Backup
quick oneRestore
, we are going to take advantage of the functionality that it hasInnoDB
to be able to discard and import the different onesTablespaces
from the database.Backup procedure:
The first step we must do to perform a
Backup
is to lock the table to be able to manipulate the files correctly:FLUSH TABLES DB1.Tabla1 FOR EXPORT
Now we will go to look for the files of the table that we have locked (
'C:\BD\Tabla1.*'
) and we will copy them to the folder where we left the backup ('C:\Copia\'
).Once the files are copied, we will unlock the table that we previously locked:
UNLOCK TABLES;
Restore procedure:
The first step we need to do is drop the
Tablespace
one from the table we are going to restore:ALTER TABLE DB1.Tabla1 DISCARD TABLESPACE;
This way the table is no longer linked to
Base de datos
and you can now manipulate the files related to that table.Now we will go to look for the files of
Backup
the table that we have discarded ('C:\Copia\Tabla1.*'
) and we will copy them in the folder where the files of the table of theBase de datos
('C:\BD\'
) are, replacing all the files.Once the files have been copied, we will import the one
Tablespace
from the table and, in this way, we will have restored the copy we had to the Database:ALTER TABLE DB1.Tabla1 IMPORT TABLESPACE;
I recommend you use either of these two tools: