HomeContact
Computerz
Move mysql to another place without losing data
René Dohmen
March 15, 2011
1 min

So you need to physically move around your mysql databases, typically because you want to put them on a another partition or hard drive, or on some network device ? This is how you can do it.

My comp runs debian unstable, but the following should apply to any recent Debian or Ubuntu distribution. First stop the mysql service :

Then go to your current mysql data directory, by default in Debian / Ubuntu it should be /var/lib/mysql. Check that your databases are there (in this example I have 2 bases - the default ‘mysql’ base and a user-created ‘wpdb’ base) :

Create a new directory for your data (in this example, the /var/www directory which is located on another partition) and give ownership on it to the mysql user :

Copy your databases to the new dir and update ownership if needed. Only move the databases dirs, don’t touch the other files.

Then update your my.conf file to make it point to the new dir :

Find the following statement :

and update with the new location :

And finally restart the mysql service

When restarting, mysql re-created files ibdata1, ib_logfile0, etc. in the new data dir. If everything went OK, you can now remove the original dir. Voilà !


Related Posts

Working with git submodules
October 15, 2023
3 min
© 2024, All Rights Reserved.
Powered by formatics

Quick Links

Advertise with usAbout UsContact Us

Social Media