Ubuntu – Mysql Datadir on different hard drive

MySQLpermissions

I'm currently running Ubuntu 13.04 and MySQL 5.5. I have been using InnoDB, and the default location for installation. The problem is that my main OS partition is fairly small (36GB), and I need to move my database to my 2TB drive.

I'm trying to change MySQL datadir from:

/var/lib/mysql

to:

/path/to/new/directory

but I've been running into all kinds of problems. MySQL refuses to start, and generally tells me there are problems with permissions. This doesn't make any sense to me, though. Here is what I have tried doing:

I copied the files:

cp -R /var/lib/mysql /path/to/new/directory

I edited /etc/mysql/my.cnf :

datadir=/path/to/new/directory

Updated the permissions:

chown -R mysql:mysql /path/to/new/directory

Updated Apparmor:

/path/to/new/directory/ r,
/path/to/new/directory/** rwk,

I make sure to reset Apparmor:

service apparmor restart

But it still gives me errors. I am not sure what else I need to do. Does anyone have a definitive guide to making this work under Ubuntu 13.04, MySQL 5.5, and InnoDB?

Best Answer

I faced the exact same problem, but I've found a better alternative that did work for me, since changing the user to root in the my.cnf file didn't work for me.

  1. First head to the MySQL data directory and move all ibdata files and all ib_logfile files to a temp folder (should look similar to mv /path_to_mysql_data_directory/ib* /path_to_temp_folder/).
  2. Run sudo service mysqld start and it should start.
  3. Run sudo service mysqld stop and it should stop.
  4. Take the file you moved to the temp folder and put them back in the MySQL data directory (should look similar to mv /path_to_temp_folder/ib* /path_to_mysql_data_directory/).
  5. Run sudo service mysqld start again and everything should start.

This solution did work for me, but I haven't tested it elsewhere.