MathJax

SyntaxHighlighter

Highlight

Custom CSS

Thursday, August 14, 2008

Moving the MySQL data directory in Ubuntu

There are lots of guides on the internet that tell you how to move your data directory. Most of them fail to mention that for Ubuntu, AppArmor will render those directions useless in a silent way. If you've followed everything to the letter, and MySQL still refuses to start for some reason, tail /var/log/syslog. If you see something like this:

May 7 15:51:55 vcke-gl-linux mysqld_safe[5886]: started
May 7 15:51:55 vcke-gl-linux kernel: [ 82.391726] audit(1210139515.249:2): 
  type=1503 operation="inode_create" 
  requested_mask="w::" denied_mask="w::" 
  name="/mnt/fastdata/var/lib/mysql/vcke-gl-linux.lower-test" 
  pid=5888 profile="/usr/sbin/mysqld" namespace="default"
May 7 15:51:55 vcke-gl-linux mysqld[5890]: 080507 15:51:55 [Warning] Can't create test file
  /var/lib/mysql/vcke-gl-linux.lower-test
May 7 15:51:55 vcke-gl-linux kernel: [ 82.393387] audit(1210139515.259:3): 
  type=1503 operation="inode_create" 
  requested_mask="w::" denied_mask="w::" 
  name="/mnt/fastdata/var/lib/mysql/vcke-gl-linux.lower-test" 
  pid=5888 profile="/usr/sbin/mysqld" namespace="default"
May 7 15:51:55 vcke-gl-linux mysqld[5890]: 080507 15:51:55 [Warning] Can't create test file 
  /var/lib/mysql/vcke-gl-linux.lower-test
May 7 15:51:55 vcke-gl-linux kernel: [ 82.487247] audit(1210139515.349:4): 
  type=1503 operation="inode_create" 
  requested_mask="w::" denied_mask="w::" name="/mnt/fastdata/tmp/ib7jXL82" 
  pid=5888 profile="/usr/sbin/mysqld" namespace="default"

...then you'll know the problem applies to you. For security reasons, AppArmor will restrict MySQL to reading and writing from certain specified directories, listed in /etc/apparmor.d/usr.sbin/mysqld. If you edit that file and add the new data directory, you'll be golden. You might also need to change mysql's home directory in /etc/passwd, or create a symlink to the new home.
Post a Comment