I want to separate MySQL database from the OS (Ubuntu) disk by moving the entire database to an exclusive HDD (M.2), and update the database folder in my.cnf.

My question is: when the MySQL folder is on a separate disk, can I safely format the OS disk and install a fresh Ubuntu (and MySQL)?

Is it OK to install a fresh MySQL and simply point to the existing MySQL folder on a different disk in the my.cnf of freshly installed MySQL?

OR the best practice is to restore the databases from a dump after a fresh install, though the database is still available in the machine?

  • 1
    I have safely moved the entire data directory to different disks and folders and updated the configuration file to reflect the new location. As long as the current version of MySQL is the same as the one that you freshly install there should not be any problems. If they ARE different you'll need to take migration between versions into consideration. – Dave Mar 1 '19 at 13:15

Yes, you can here is the steps to do it.

# service mysqld stop
# cd /var/lib/mysql
# tar -cvzf /tmp/mysql-backup.tar.gz ./*
# service mysqld start


# service mysqld stop
# cd /data/mysql
# tar -xvzf /tmp/mysql-backup.tar.gz
# service mysqld start


  1. Cold backup will not work if you try to restore it in older versions of MySQL it will be better if you use the same version.
  2. You need to make sure new directory is owned by MySQL user and it has the needed permission
  3. New datadir is accurate inside my.cnf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.