Tag Archives: data directory

MySQL: Ubuntu Server 9.04, moving the data directory to a different location

I recently deployed a “custom” server, will be used primarily as a MySQL server, using software RAID 5 for storage reliability.

I’ll try to explain in the future how I deployed the software RAID…

Anyway, my RAID partition is mounted in /data, I’m planning to store all MySQL files in sub-directory inside it, /data/mysql/

After changing the relevant MySQL variables in /etc/mysql/my.cnf,

[mysqld]
port            = 3306
datadir         = /data/mysql
socket          = /var/run/mysqld/mysqld.sock
<<< … truncated data … >>>
innodb_data_home_dir = /data/mysql/
innodb_data_file_path = ibdata1:500M;ibdata2:10M:autoextend
innodb_log_group_home_dir = /data/mysql/
innodb_log_arch_dir = /data/mysql/
innodb_buffer_pool_size = 4000M

I attempted to start MySQL but all I have is this,

root@****:~# /etc/init.d/mysql start
 * Starting MySQL database server mysqld
   …fail!


I am more familiar with RHEL/CentOS, been using it in our servers for years now, so the first thing that comes to mind is SELinux. This is the first time that I’m going to deploy an Ubuntu Server, in short, I’m a newbie.

Note: Realization came later that Ubuntu’s server deployment doesn’t use SELinux, it’s using a counterpart called AppArmor.

Looking at /var/log/messages, I got these messages,

May 10 13:52:38 ****server kernel: [ 9495.640883] type=1503 audit(1241934758.732:11): operation=”inode_create” requested_mask=”a::” denied_mask=”a::” fsuid=0 name=”/data/mysql/****server.lower-test” pid=18791 profile=”/usr/sbin/mysqld”
May 10 13:52:38 ****server kernel: [ 9495.640944] type=1503 audit(1241934758.732:12): operation=”inode_create” requested_mask=”a::” denied_mask=”a::” fsuid=0 name=”/data/mysql/****server.lower-test” pid=18791 profile=”/usr/sbin/mysqld”

These messages are not from SELinux at all, something is preventing /usr/sbin/mysqld from writing in /data/mysql/

A little googling led me to this blog [neodon.blogspot.com] and this blog [brainwreckedtech.wordpress.com].

One of the entries there said that I have to edit AppArmor’s MySQL policy (aha!, so it’s AppArmor!)

root@****:~# vi /etc/apparmor.d/usr.sbin.mysqld

Inside it, I added /data/mysql/, the blue one (don’t ask me what the line means, I don’t have the exact idea, I only assumed it has something to do with read/write permissions).

/usr/sbin/mysqld {
  #include

  #include

  #include

  #include

  #include

  <<< … truncated data … >>>

  /var/log/mysql.err rw,
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
  /data/mysql/** rwk,
  /var/log/mysql/ r,
  /var/log/mysql/* rw,
  /var/run/mysqld/mysqld.pid w,
  /var/run/mysqld/mysqld.sock w,
}

Then restarted AppArmor,

root@****:~# /etc/init.d/apparmor reload
 * Reloading AppArmor profiles …
   …done.


and now it’s working!

root@****:~# /etc/init.d/mysql start
 * Starting MySQL database server mysqld
   …done.