Fixing MySQL error 29 (ErrCode: 13) in Ubuntu

Ubuntu 12.04 Recently I had to work with a large amount of data that had to be imported into MySQL via a script after being modified. I’ve found that using LOAD DATA was the quickest way to do the job.

If you are using Ubuntu for your server (or you have to work with a server using Ubuntu) you will find this error when trying to use the query:

ERROR 29 (HY000): File '....' not found (Errcode: 13)

After few seconds on Google you will find many users that managed to get over the error using the keyword LOCAL, but if you keep your MySQL updated you will see that it will not work as it could generate a security issue in your server.

To overcome this issue there is a simple workaround that require you to modify the MySQL’s AppArmor file and define directory where the program can read and write.

Be aware that allowing MySQL to read and write in a directory could lead to security problems, always review this kind of changes with a System Administrator.

The workaround is really quick:

  1. Open the file /etc/apparmor.d/usr.sbin.mysqld as root with your favourite text editor
  2. You should see a list of paths where AppArmor allow MySQL to write and read, at the end of this list add the directory where you would like that MySQL will be able to read and write following the pattern used in all the previous entries. For instance:
    #Other contents
    /usr/sbin/mysqld {
    
        #Other contents
    
        /var/log/mysql.log rw,
        /var/log/mysql.err rw,
    
        #Other contents
    
        #This will be your dir definition
        /tmp/ r,
        /tmp/* rw,
    
        #Other contents
    }
    

    Then save and close the file.

  3. After you have successfully modified the file it is time to tell AppArmor that it needs to reload the configurations, so as root execute the following command:
    # /etc/init.d/apparmor reload
  4. Then restart MySQL, as root execute the following command:
    # service mysql restart

At this point you have allowed MySQL to write and read contents into your defined directory, only do this if you know what you are doing! I take no responsibility for any damage or data loss caused by a server not correctly secured.

Be careful & have fun!

Advertisements

8 thoughts on “Fixing MySQL error 29 (ErrCode: 13) in Ubuntu

  1. Hi, I tried your solution but it does not work for me yet. I followed exactly what you said, but I have doubts regarding what I should write inside the file usr.sbin.mysqld.

    I’m trying to import a table located at ‘/disk/local/users/nhern121/Desktop/ElanceData/jobbiddertable/BidderList.csv’

    SO, what I did was to type
    /disk/local/users/nhern121/Desktop/ElanceData/jobbiddertable/ r,
    /disk/local/users/nhern121/Desktop/ElanceData/jobbiddertable/* rw,

    at the bottom of the file, and then restart as you said, but I’m still getting the same error in MySQL.

    I would appreciate your help a lot. I’ve been struggling with these for the last two days.

    Thank you.

    Best

  2. Pingback: Mysql load data 命令解析、处理 error 29 (ErrCode: 13) 错误(在ubuntu环境下) - 数据库 - 阿里欧歌

  3. Pingback: Mysql load data 命令解析、处理 error 29 (ErrCode: 13) 错误(在ubuntu环境下) | 你好数据库

  4. Hola, muchas gracias por tu solución, los intentos anteriores con otras soluciones tratando de cambiar los permisos no me funcionaron, un saludo.

    Hello, thanks a lot for your solution, previous attempts with other solutions trying to change permissions didn’t work, regards.

Your opinion is important!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s