Can’t create/write to file ‘/mnt/temp/something’ (Errcode: 13)

amazon ec2amazon-ebsmysql5.5tmpubuntu-12.04

I changed the tmp directory of the mysql configuration to a mounted disk and on service mysql restart I get following error:

Can't create/write to file '/mnt/temp/something' (Errcode: 13)

To my understanding, Error Code 13 refers to file permission error.

But strange part is:

  1. temp directory owner is already mysql and file permission is 1777

    drwxrwxrwt 2 mysql mysql 4.0K Nov 14 08:34 temp/

  2. I am able create file in the location with a non root user.

  3. There is 600 Gb of space on mnt so that should not be an issue.

  4. I can create tmp directory easily on root disk

/etc/mysql/my.cnf:

user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /mnt/mysql
tmpdir          = /mnt/temp
#tmpdir         = /var/tmp

Is creating a tmp directory on a mounted disk not allowed? Or else what am I doing wrong? Pls help.

Best Answer

So this is a little old, but I just solved a similar problem, myself (Using /mnt/tmp as the system temp dir) and had to figure out why MySQL wouldn't start up.

You're probably running up against the AppArmor settings that prevent MySQL from using directories on the /mnt drive. You'll need to add your new tmp path to the MySQL app armor list of allowed paths.

If you look in your syslog, you'll probably see messages looking something like this every time you try to start the mysql server:

type=1400 audit(1425343954.203:23): apparmor="DENIED" operation="mknod" parent=1 profile="/usr/sbin/mysqld" name="/mnt/tmp/ibMXP5lg" pid=16418 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=106 ouid=106

In this case, You'll need to edit the file:

/etc/apparmor.d/usr.sbin.mysqld

And add the lines:

/mnt/tmp/ r,
/mnt/tmp/** rwk,

to the file. Then just restart AppArmor:

$ sudo service apparmor restart