Tag Archives: error-29

The MySQL load data command parses and handles error 29 (errCode: 13) errors (in the Ubuntu environment)

On the mysql server, you can use the following command:

load data infile 'file_name' into table table_name; 

Stores all data in a text file into the specified table. The crudest form of example:

load data infile 'test.txt' into table test_table;

By default, the Load Data Infile behavior for text is:
A

    row corresponds to a record in the database table separated by the TAB key the value of each field is not enclosed by any characters and the row is not prefixed to ignore

For example, a line of text:
1 test “xx”
reads into the database, and the value of the third field is “xx” instead of xx. Of course these fields can be set, the full Load Data Infile command is:

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
   [REPLACE | IGNORE]
  INTO TABLE tbl_name
   [FIELDS
    [TERMINATED BY 'string']
   [[OPTIONALLY] ENCLOSED BY 'char']
   [ESCAPED BY 'char' ]
 ]
   [LINES
   [STARTING BY 'string']
  [TERMINATED BY 'string']
  ]
   [IGNORE number LINES]
  [(col_name_or_user_var,...)]
   [SET col_name = expr,...]]

Ignore and replace are used to distinguish between the way in which the text is read and the record in the original table that has a primary key conflict. The terminated by setting field (delimiter) after
fields, enclosed by setting outer enclosing characters, and escape by setting escape characters (this is unclear).
lines, starting by sets the line prefix, will be ignored when reading, and the newline character is set. Refer to the first link for more details.
Then in the process of use, it is easy to have errors:
ERROR 29 (HY000): File ‘test.txt’ not found (Errcode: 13) But it is of no damn use From the command line you can see that errcode 13 refers to the access issue:

xyb@xyb-computer:~$ perror 13
OS error code 13: Permission denied

Even if you change the access to the test.txt file, such as chmod O +r test.txt, the problem will still occur. It involves AppArmor. This is a protection mechanism that restricts each program’s access to specific directories and files. In other words, it is restricted by AppArmor, which provides access to the file for the current mysql program. See link to article 2 about AppArmor (Wikipedia).
can really do is to mysql program reads the file permissions, according to the following steps can be done:
1) open the/etc/apparmor. D/usr. Sbin. Mysqld file
2) can see a lot about mysql can read and write at this time for the directory and file records, such as:

#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
}

Add the appropriate permissions for the file you want to read and write at the end, save and exit. D/AppArmor reload
. At this point, the problem should be solved. But this can be an unsafe solution and requires caution. Refer to the third link for details.
Reference links:

https://en.wikipedia.org/wiki/AppArmor http://www.2cto.com/database/201108/99655.html https://oldwildissue.wordpress.com/2013/12/11/fixing-mysql-error-29-errcode-13-in-ubuntu/