Mysql load data command parses and processes error 29 (ErrCode: 13) (In ubuntu environment), errcodeubuntu

Source: Internet
Author: User

Mysql load data command parses and processes error 29 (ErrCode: 13) (In ubuntu environment), errcodeubuntu

On the mysql server, run the following command:

load data infile 'file_name' into table table_name; 

Store all data in a text file in a specified table. Example of the most rough form:

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

By default, load data infile performs the following operations in text:

For example, a line of text:
1 test "xx"
After the database is read, the value of the third field is "xx", not xx. Of course, you can set these fields. The complete 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 differentiate the processing method of records with primary key conflicts between the read text and the original table.
Terminated by after fields sets the field terminator (separator), enclosed by sets the exclusive character, and escape by sets the escape Character (this is not very sure ).
Set the line prefix for starting by after lines, ignore it during reading, and set the line break for terminated. For more details, see the first link.

Then, errors may easily occur during use:
ERROR 29 (HY000): File 'test.txt 'not found (Errcode: 13)
There are a lot of online saying that adding the local keyword in the command is a pity on my computer... And... In the command line, you can see that errcode 13 indicates an access permission problem:

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

The access permission of the test.txt file is changed. For example, the above problem still occurs in chmod o + r test.txt. To solve this problem, we will talk about AppArmor. This is a protection mechanism that limits the access permissions of each program to a specific directory and file. That is to say, the current mysql program's permission to access this file is restricted by AppArmor. For more information about AppArmor, see the second link (Wikipedia ).
What we can do is to grant the mysql program the permission to read this file. follow these steps:
1) Open the/etc/apparmor. d/usr. sbin. mysqld file.
2) Now we can see a lot of records about mysql reading and writing as directories and files, such:

#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 corresponding permissions of the file to be read and written at the end, save and exit.
3) re-import the AppArmor configuration and use the/etc/init. d/apparmor reload command
4) restart mysql and use the service mysql restart command
This problem should be solved. However, this may be an insecure solution, so be careful. For more information, see the third link.

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.