I have Ubuntu Desktop 11.04 and I'm trying to move /var/lib/mysql to a TrueCrypt volume and am failing at every attempt.

This is for development purposes, and there's a particular database I need to work with that needs to be highly secure for numerous reasons.

Upon a fresh install of mysql-server and mysql-client, I'm able to start mysql without any problem. So I then move /var/lib/mysql to the TrueCrypt volume (call it /foo/truecrypt), and then edit /etc/mysql/my.cnf to point datadir to /foo/truecrypt.

After I check permissions to make sure that they are the same, I try to start mysql again.

It doesn't work (MySQL just continues to hang), and I'm unable to get MySQL to work again (even after killing all mysql processes and moving the datadir back to /var/lib/mysql). I've done a apt-get --purge remove mysql-client mysql-server mysql-common (and then deleted all files in /var/lib/mysql, etc/mysql/ and /var/log/mysql*) at least 5 times tonight in order to get a fresh install to try again.

While MySQL hangs, I've gone into /var/log/mysql/ and here's what shows up in mysql.err:

120421 22:50:03 [Note] Plugin 'FEDERATED' is disabled.
^G/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
120421 22:50:03 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120421 22:50:03  InnoDB: Initializing buffer pool, size = 8.0M
120421 22:50:03  InnoDB: Completed initialization of buffer pool
120421 22:50:03  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

I've tried moving /var/lib/mysql/ and then creating a symlink instead of editing my.cnf. That doesn't make a difference. The errors above indicate a missing file or permissions issues. However, plugin.frm exists in /foo/truectrypt/mysql/mysql (as I simply just moved the parent directory), and ownership and permissions on that and all other files in that directory are the same as they were.

Do you have any suggestions? I'm stumped.

2 Answers 2


I've never attempted to do exactly what you are doing, but I have set up mysql databases that would be accessible regardless of which OS I booted to. I did this by moving /var/lib/mysql/database to a shared partition /shared/database and then symlinked the directory back to /var/lib/mysql/database. If that procedure doesn't work for you, then I'd look into whether or not symlinking works at all with TrueCrypt (it should).

The file mentioned in the error (ibdata1) exists in /var/lib/mysql so I can only imagine that you moved one directory to many up the tree. Don't move /var/lib/mysql, move the specific directory for your database /var/lib/mysql/database

  • Well, these are both good thoughts (symlinking w/ TrueCrypt, and making sure the directory tree remains consistent), but I was moving the entire mysql data directory, intending for all of the databases to be on the TrueCrypt volume. That's a good suggestion to move just the 1 database, but I'd have to somehow get my.cnf to point to the TrueCrypt volume for that 1 DB, and point to the main data dir for other databases. I'll play around with this idea. Thanks.
    – David W
    Apr 22, 2012 at 12:44
  • The symlink should do that for you, no need to modify my.cnf. For all intents and purposes symlinks to things are the things they point to. Unless applications are specifically looking, they can't tell the difference.
    – Huckle
    Apr 22, 2012 at 19:38

The issue was with AppArmor, which I've never had experience with. I (finally) found an obscure website that said the following:

Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.

(from http://article.my-addr.com/?show=linux_ubuntu_change_datadir-move_mysql_database_to_other_path)

I needed to edit /etc/apparmor.d/usr.sbin.mysqld as follows:

After following the instructions to "Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadir", and then symlinking /usr/new_datadir to /var/lib/mysql, it works like a charm!

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.