I need to move my data directory to a bigger drive on the same server.

# stop mysql
/etc/init.d/mysql stop

# copy the data over
cp -R -p /var/lib/mysql /home/mysql

#edit my.cnf
# and add a 'datadir' section with the new path.

#restart mysql
/etc/init.d/mysql restart

The copying of the data will take ages, (I suspect), but at least it will be safe.

I might also want to add a temp directory somewhere.

Do I need to do anything else to move the data.

Will I need to rebuild indexes or something else?

  • 1
    Important - check the user and permissions - the datadir should be owned by the mysql user and group and entire path has to be accessible by that user (should not be a problem with /home) and then check if you are running apparmor or selinux and if it will allow mysql to access that directory. No need to rebuild anything if it starts.
    – jkavalik
    Commented May 8, 2016 at 17:38
  • 1
    Although unlikely but mind that innodb specific parameters innodb_log_group_home_dir and innodb_data_home_dir can have different values than datadir. Make sure these are not set or repointed too. Also in case you have replication then check log-bin directory. Commented May 8, 2016 at 19:35

1 Answer 1


Ideally you would keep that folder, and instead of changing it you'd either mount another folder or partition on it prior to starting mysql, or create a symlink elsewhere (there are answers for doing this here and here).

You won't need to rebuild anything for moving your files, but it is a good idea to always make a backup before attempting something like this that may damage your data if anything goes wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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