Mysql Can't create/write to file error#13 Mysql Can't create/write to file error#13 django django

Mysql Can't create/write to file error#13


It is probably a permission issue for the temporary folder that is used by Mysql.

You can find the folder used by Mysql for temp operations in the config file in /etc/mysql/my.cnf as such :

tmpdir          = /tmp

As you can see, the temp folder in use by default is "/tmp".

Privileges should be :

drwxrwxrwt   9 root root  4096 oct.  24 15:39 tmp/

So anybody, including the "mysql" user, can use it.If not correctly set, the following command would do the trick :

chmod 0777 /tmp

Hope this helps !


If after giving necessary write permissions to the new tmpdir you're still having the same error - and mysql therefore can't start - you might have AppArmor enabled. So do :

sudo vim /etc/apparmor.d/local/usr.sbin.mysqld

Of course you can use any text editor other than vim eg nano. Note that usr.sbin.mysqld at the end corresponds to what you get by doing which mysql or which mysqld (with / replaced by .). When the file is open, you'll see some comments at the top like :

# Site-specific additions and overrides for usr.sbin.mysqld.# For more details, please see /etc/apparmor.d/local/README.

Then put after those comments :

/path/to/new/tmp/dir/ r,/path/to/new/tmp/dir/** rwk,

And then do : sudo service apparmor reload. Now try starting mysql : sudo service mysql start and you should be good to go.


You have configured mysql's tmpdir to point to a directory the server does not have permission to write to.

For small filesorts, MySQL uses an in-memory buffer, but for larger ones uses files on disc (in the tmpdir).

In any case, it is a sysadmin error (not a programming error) setting the MySQL tmpdir to point to a unwritable directory.