QA:How to restore data in MySQL or MariaDB

From FedoraProject

(Difference between revisions)
Jump to: navigation, search
(Restoring the data)
 
Line 13: Line 13:
 
<pre>
 
<pre>
 
$ mysql -u root -p < backup.sql
 
$ mysql -u root -p < backup.sql
 +
$ mysql -u root
 +
mysql> FLUSH PRIVILEGES;
 
</pre>
 
</pre>
  

Latest revision as of 13:02, 30 April 2013

For restoring backed-up data choose one of the methods bellow, depending which way you have chosen for back-up.

Contents

[edit] Restoring from a dump file

Suppose you have backed-up data into a dump file backup.sql

[edit] Prerequisites

  • make sure a user you are connecting to a database under has enough privileges to create all backed-up tables

[edit] Restoring the data

$ mysql -u root -p < backup.sql
$ mysql -u root
mysql> FLUSH PRIVILEGES;

[edit] Restoring from copied binary files

Warning (medium size).png
When to use copying binary files
Copying pure binary files as a backup should work fine in case we will restore them on the same minor version of MySQL or MariaDB daemon. So it is OK to move data stack this way when switching from MySQL to MariaDB or back, but you should use dump and restore alternative when ugrading from 5.1 to 5.5 or similar.

Suppose you have copied the data stack to a location /save/directory/mysql. We should also pay attention on SELinux context, so running restoreconf is a good idea.

# cp -r /save/directory/mysql /var/lib/mysql
# restoreconf -r /var/lib/mysql

[edit] Expected results

After starting the database daemon the data will work.