Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently moved my MySQL database data directory from the default location /var/lib/mysql onto a new harddrive located in /media/..UID../mysql, following the steps you can find in several posts.

  1. stop the MySQL
  2. Copy the old folder to the new location
  3. Change the datadir in the [mysqld] of /etc/mysql/my.cnf
  4. Change the two entries in the AppArmor configuration
  5. Adjust the user rights from the data dir
  6. Restart AppArmor
  7. Restart MySql

After those steps I tried to create a new database and it worked, it appears also in the new folder. Then I created a new InnoDB table and it also worked and it places the *frm file into the /mysql/new folder. But then I wanted to create a MyISAM table into this database, I received the error

#1 - Can't create/write to file '/media/..UID../mysql/new/tableName.MYI' (Errcode: 13)

I tried already to set all permission to 777, as I thought it is a permission problem (but as InnoDB can write into that folder, I cannot see why MyISAM cannot!?). For me it looks like that the MyISAM engine needs somewhere else special permission in order to write it's files, but I do not know where.

First I thought that it is a mounting problem of that new harddrive, but then again - the InnoDB can create database folders and also create files inside these folders.

So, any help is appreciated, if someone had a similar issue after moving a MyISAM table and could give some hints where to look or what else to try.

Thanks a lot already in advance!

share|improve this question
up vote 1 down vote accepted

I had similar problem.

Here are my steps that did work on Ubuntu 12.04 Lts:
Want to move datafiles from /var/lib/mysql to /newdir_path/newdir

  1. sudo mysql stop
  2. sudo rsync -av /var/lib/mysql /newdir_path/newdir ## like copy, but keeps rights
  3. sudo gedit /etc/mysql/my.cnf, change datadir to /newdir_path/newdir
  4. sudo gedit /etc/apparmor.d/usr.sbin.mysqld, change:
      instead of:
      • /var/lib/mysql/ r,
      • /var/lib/mysql/** /rwk
      • /newdir_path/newdir/ r,
      • /newdir_path/newdir/** rwk,
  5. sudo /etc/init.d/apparmor restart
  6. (!!!) sudo chown mysql:mysql /newdir_path
  7. sudo start mysql
share|improve this answer
Thanks for the answer after so long time, unfortunately I reinstalled the computer in the meanwhile and solved the problem that way. But once I have to move the DB again, I am happy to try out your steps. As I cannot try it right now, I am going to accept this solution as possibly working. – Daniel Fischer Sep 18 '13 at 7:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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