4.2.3 Restoring a Database

Delete all files inside the server's data directory. If the
data directory is not empty, you have to use the
--force option to allow
overwriting of the old data, or
mysqlbackup will error out.

Use, for example, the
copy-back-and-apply-log command,
which converts the raw backup into a prepared backup by
updating it to a consistent state, and then copies the
tables, indexes, metadata, and any other required files onto
a target server. For the various options that you can
specify for this operation, see
Section 14.3, “Restore Operations”.

--defaults-file supplies
the configuration for restoring the data. It must be the
first option to appear in a mysqlbackup
command, if ever used. In most cases, you can supply to
mysqlbackup with this option the
configuration file for the target server to which you are
restoring the data. However, when the following InnoDB
settings for the backup are different from those on the
target server, it is important to supply the values for
the backup to mysqlbackup during
restore and to mysqld when you start
the restored server (otherwise, the restore might fail,
and you might have problem starting the restored server):

If you are not sure about those settings for your backup,
they are stored in the backup-my.cnf
file during the backup—you can find the file either
in the temporary directory you specified with
--backup-dir
when you created the single-image backup, or in a backup
directory you can create by unpacking the backup image
using the
extract
command. If the values of these options differ from those
on the target server, add them to the configuration file
you are supplying to mysqlbackup and
also to the configuration file you are going to use to
start the server afterwards; alternatively, you can also
supply them as command line options to
mysqlbackup and
mysqld.

For some of the options listed above (namely,
innodb_data_file_path,
innodb_log_file_size,
innodb_log_files_in_group,
and
innodb_undo_tablespaces),
mysqlbackup checks the values you
supply for them to ensure that you will be able to start
the target server afterwards with those values: it throws
an error if any of them does not match with the actual
values for the backup. Warnings are given if those values
are not specified for mysqlbackup in
either the configuration file or on the command line
(which is the case in the example below).

--datadir supplies the
location of the data directory for restoring the data. You
must specify this option for any restore operation.

Now the original database directory is restored from the backup.
Depending on how you are going to start the restored server, you
might need to adjust the ownership of the restored data
directory. For example, if the server is going to be started by
the user mysql, use the following command to
change the owner attribute of the data directory and the files
under it to the mysql user, and the group
attribute to the mysql group.