Mysql Load Data command parsing, handling error (ERRCODE:13) errors (in Ubuntu environment)

Source: Internet
Author: User
Tags reserved file permissions

On the MySQL server, you can use the load data infile ' file_name ' into table table_name; command to save all the data in a text file to the specified table. Examples of the most sketchy forms:
Load data infile ' test.txt ' into table test_table;
By default, load data infile behaves in the text:

    1. A row corresponds to a record in the database table
    2. Tab key for each field
    3. The value of each field is not enclosed by any characters.
    4. Rows without prefixes can be ignored

For example, a line of text:
1 Test "XX"
After a database is read, the value of the third field is "XX", not xx. Of course these fields can be set, the full load Data infile command is:

‘file_name.txt‘   [REPLACE | IGNORE]  INTO TABLE tbl_name   [FIELDS    ‘string‘]   ‘char‘]   ‘char‘ ] ]   [LINES   ‘string‘]  ‘string‘]  ]   [IGNORE number LINES]  [(col_name_or_user_var,...)]   [SET col_name = expr,...]]

Ignore and replace are used to distinguish between when a record is read into the text and the primary key conflict in the original table.
The terminated by setting field Terminator (delimiter), enclosed by setting the escape character (which is not quite certain) is set by an outer character.
Lines after the starting by setting the line prefix, read in when ignored, terminated by set newline character. For more details, refer to the first link.

Then in the process of use, it is easy to get errors:
ERROR (HY000): File ' test.txt ' not Found (errcode:13)
There are a lot of online words in the command to add the local keyword, unfortunately on my computer ... And then the egg ... At the command line you can tell that Errcode 13 refers to access rights issues:
[Email protected]:~$ perror 13
OS error code 13:permission denied

Even if you change the access permissions for the Test.txt file, such as chmod o+r test.txt, this problem still occurs. To solve this problem will be AppArmor. This is a protection mechanism that restricts each program's access to specific directories and files. That is to say, the current MySQL program access to this file permissions are AppArmor limited. About AppArmor refer to the second link (wikipedia).
What really can be done is to give the MySQL program permission to read this file, follow these steps to do:
1) Open/etc/apparmor.d/usr.sbin.mysqld file
2) You can see a lot of records about MySQL being able to read and write to directories and files, 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}

At the end, add the appropriate permissions for the file you want to read and write, and save and exit.
3) Re-import AppArmor configuration with/etc/init.d/apparmor reload command
4) Restart MySQL, using the service mysql restart command
The problem should be solved. However, this may be an unsafe solution and requires caution. Refer to the third link for details.

Reference Links:
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/

Mysql Load Data command parsing, handling error (ERRCODE:13) errors (in Ubuntu environment)

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.