Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 501
Matteo Riva Avatar asked Mar 20 '10 09:03

Matteo Riva


People also ask

Can I copy var lib MySQL?

Rename the /var/lib/mysql folder, e.g. to /var/lib/_mysql. Copy the old /var/lib/mysql folder from the old Debian (LMDE) system. sudo systemctl start mysqld . -> Job for mysqld.

What is var lib MySQL?

Usually /var/lib/mysql or /var/db/mysql directory used to store database and tales under UNIX like operating systems. You can use the following command to locate MySQL datadir: grep datadir /etc/my.cnf. datadir=/var/lib/mysql. Or.


3 Answers

  • 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).

like image 61
Etienne Dechamps Avatar answered Oct 16 '22 20:10

Etienne Dechamps


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.

like image 23
AlBlue Avatar answered Oct 16 '22 18:10

AlBlue


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.

like image 3
Joonas Pulakka Avatar answered Oct 16 '22 19:10

Joonas Pulakka