Total: £0.00

MySQL - SELECT * INTO OUTFILE from phpmyadmin - Can't create/write to file (Errcode: 13)

By marksams, 06/02/2011 - 19:54

Whilst trying to export some data to a file from MySQL using phpmyadmin with the SELECT * INTO OUTFILE command, I received the following error:

#1 - Can't create/write to file '/path/to/file' (Errcode: 13)

After messing around with chmod and chown for a bit I started to search the internet. The error wasn't caused by the MySQL tmpdir variable either - it was apparmor. To resolve this error I had to edit the apparmor config file for MySQL and restart the MySQL service as follows:

  • Edit the config file

    • sudo nano /etc/apparmor.d/usr.sbin.mysqld
  • Following the same syntax as the other entries, add a line for your specific directory

    • /path/to/the/specific/directory/you/want/to/save/file/in/* w,
  • Restart MySQL

    • sudo service mysql restart

NOTE: The directory permissions also needed for this to work were set to 755 and with the owner/group set to 'mysql'.

  • Change directory permissions

    • sudo chmod 755 mydirectory
  • Change owner/group

    • sudo chown mysql:mysql mydirectory