Is copying the /var/lib/mysql directory a good alternative to mysqldump?
Asked Answered
A

5

43

Since I'm making a full backup of my entire debian system, I was thinking if having a copy of /var/lib/mysql directory is a viable alternative to dumping tables with mysqldump.

  • are all informations needed contained in that directory?
  • can single tables be imported in another mysql?
  • can there be problems while restoring those files on a (probably slightly) different mysql server version?
Automatic answered 20/3, 2010 at 9:17 Comment(2)
Doing this for years, no inconsistency!Etom
Percona has a tool that basically takes this approach for doing "hot backups" of running servers: percona.com/doc/percona-xtrabackup/2.1Weekday
R
38
  • Yes
  • Yes if the table is using the MyISAM (default) engine. Not if it's using InnoDB.
  • Probably not, and if there is, you just need to execute mysql_upgrade to fix them

To avoid getting databases in a inconsistent state, you can either shutdown MySQL or use LOCK TABLES and then FLUSH TABLES before the backup. The second solution is a little better because the MySQL server will remain available during the backup (albeit read only).

Ripplet answered 20/3, 2010 at 9:54 Comment(2)
Thanks everybody for this solution. It's cut out at least an hour of re-importing time ! And if you want to do it into one instruction: Type "FLUSH TABLES WITH READ LOCK;".Pernicious
Can you go into details on the answer for "can single tables be imported into another mysql"? "Yes so long as it's MyISAM" is a rather sparse answer.Bradley
P
6

This approach is only going to work safely if you shut the database down first. Otherwise you could well end up in an inconsistent state afterwards. Use the /etc/init.d/mysql stop command first. You can then restart it after the backup is taken.

Patti answered 20/3, 2010 at 9:57 Comment(0)
M
3

It's perfectly OK as long as you shut down the MySQL sever first and use exactly the same version to retrieve the "backup". Otherwise it isn't.

Matteson answered 20/3, 2010 at 9:54 Comment(0)
A
1

For a complete discussion of the 2 strategies, you need to read this: https://dev.mysql.com/doc/refman/5.5/en/backup-types.html

The currently best free and open-source solution seems to be Percona's: http://www.percona.com/software/percona-xtrabackup

Araxes answered 20/4, 2014 at 20:16 Comment(0)
Y
0

I'll go with a strong NO.

From my experience, backing up/restoring raw mysql data files can be used only on the same os/server version. It does not work cross platform (eg. ubuntu/macos) with same server versions nor if mysql server versions are different on same platform.

Percona XtraBackup (innobackupex) from Percona MySQL distro will let you do live & differential mysql backup and serve you the backup files that can be restored by copying to /var/lib/mysql/. You need to be running Percona Server for MySQL to use all of this.

Yacano answered 2/6, 2019 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.