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/
Read More:
- mysql load data infile ERROR 13 (HY000): Can’t get stat of
- Solution to MySQL workbench error 1148 unable to load local data
- Solution to errors reported by TES command in vscode – errors reported by typescript command
- ERROR 1148 (42000): The used command is not allowed with this MySQL version
- MySQL error — multiple methods of failed to find valid data directory and MySQL setting password appear
- [MySQL] [serialize] [error record] after modifying data, no data will be returned (in fact, MySQL does not support it)
- The solution of duplicate entry ‘for key’ primary ‘when inserting data in MySQL
- MySQL operation and maintenance slave_ skip_ errors
- Talking about the errors encountered in installing MySQL ODBC (error 1918)
- Failed to load response data:No data found for resource with given identifie
- Configuring C + + environment with atom under ubuntu1404
- Connection between PHP 7.4 and MySQL (MariaDB) under Ubuntu (kali Linux)
- To solve the problem of failed to load: data in HTML5 game running rmmv locally/ actors.json problem
- [Solved] caffe Error: Check failed: cv_img.data Could not load
- How to solve “import cv2 failed ImportError: DLL load fail: Cannot find the specified module” in Anaconda environment
- [Solved] SpringBoot Integrating Oracle reports errors: ORA-12504, TNS:listener was not given the SID in CONNECT_DATA
- [error handling] when logging into MySQL with CentOS command, an error 1045 (28000) is reported
- Solution of MySQL data garbled problem
- [solution] a perfect solution to the problem of failed to load module “Canberra GTK module” in Ubuntu
- The problem of Chinese garbled data in MySQL