Mysql – Import or restore MySQL databases from var directory

MySQLosx-snow-leopard

I recently backed up my entire laptop hard drive with SuperDuper and reinstalled Snow Leopard. Because I made an image clone, I was able to restore all my files without losing any data. Go hard drive cloning.

However, the one thing I forgot to do was to do a dump of all my MySQL databases. Eek. Because of the nature of MySQL's storage, I can't just drag and drop the databases and tables—all the data is locked up in the server.

When I mount the cloned image I can navigate to /Volumes/laptop/usr/local/mysql/var (since I had installed MySQL to /usr/local/mysql) and I can see all my databases listed as directories with random files inside, which seems promising.

What should I do to restore all those databases I forgot to dump? Is there a way to restore the var/ folder to my new, fresh installation of MySQL and (hopefully) maintain all the users and privileges? Can I just copy that directory and have everything work?

Best Answer

Disclaimer: I can't guarantee that this works for you too, it did for me.

I've done similar restorations (under Windows, though) by simply copying the files (the whole /usr/local/mysql directory...shouldn't that be under /var/mysql anyway?). Of course you'll need to stop the MySQL daemon and restart if after you're done.

Also, check the file permissions, just in case that something has changed.

Related Question