I'm trying to move the location of database files from /var/lib/mysql to /home/lib/mysql

I only changing database files. Socket is still /var/lib/mysql/mysql.sock (only changing datadir in my.cnf)

Now, all data in /var/lib/mysql has been copied to /home/lib/mysql

MySQL has been started and everything is fine. Now time to cleaning up data in /var/lib/mysql

but I'm not sure what data can and cannot be removed in /var/lib/mysql

this is data (except database name) in /var/lib/mysql:

  • One thing you can do is let mysql run for a bit... if it's still writing to those files for something, their modification times will be updated. You might be able to use access times to determine if mysql is reading from the file, but if you have a backup process or anything else accessing those files it will be less helpful.
    – DerfK
    Dec 23, 2010 at 16:57

2 Answers 2


After successfully moving your data dir, you can just delete the whole folder and its files/subfolder.

$sudo rm -rf /var/lib/mysql

You just need to double-check you have all the data.

  • I agree. I usually just move the directory instead of copying its content. Dec 23, 2010 at 15:32
  • I did that and now: sudo mysqld --initialize mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 13 - Permission denied) big sigh...
    – v.oddou
    Mar 10, 2018 at 10:54
  • fixed it by deleting /etc/mysql + deluser mysql + apt-get remove/purge & reinstall.
    – v.oddou
    Mar 10, 2018 at 11:10

ibdata1 ib_logfile0 ib_logfile1

is related with the inoddb engine used by mysql to store data.

look into /etc/my.cnf (or where ever is my.cnf) to see where is configured inoddb to put hist data.

look for some things like

innodb_data_home_dir = /var/lib/mysql/ibdata
innodb_data_file_path = ibdata1:1500M:autoextend
innodb_log_group_home_dir = /var/lib/mysql/iblog
innodb_log_arch_dir = /var/lib/mysql/iblog

once you have all set into my.cnf you can restart mysql to take effect. also right now you can look into the new location if inoddb makes data and log files and into the old location if updates the files.

don't delete those files unless you are done with the migration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .