MySQL using LOAD DATA INFILE quickly import file

load data infile statement from a text file read at high speed into a table.
Before using this command, mysqld process (service) must have been in operation. For security reasons, when reading text files located on the server, the file must be in the database directory or be readable by all.
In addition, in order to use load data infile files on the server, on the server host you have to have the file permissions.

SQL statements

基本语法
load data  [low_priority] [local] infile 'file_name txt' [replace | ignore]
into table tbl_name
[fields
[terminated by't']
[OPTIONALLY] enclosed by '']
[escaped by'\' ]]
[lines terminated by'n']
[ignore number lines]
[(col_name,   )];

简单示例
load data infile '文件路径' low_priority  into table 表名 
character set utf8mb4 
fields terminated by ',' 
Enclosed By '"' 
LINES TERMINATED BY '\n' (`字段列表`);

low_priority
If you specify the keyword low_priority, then MySQL will wait until there are no other people when reading this table, only then insert the data.

replace and ignore duplicate keywords control process unique key existing record. If you specify replace, new rows replace existing rows with the same unique key value. If you specify ignore, skip the input duplicates existing line of unique keys. Either option if you do not specify when to find duplicate keys, an error, and the rest of the text file is ignored
for the addition of a unique index field

character set utf8mb4
set encoding format, to prevent distortion Chinese (or not provided)

fields terminated by ','
specify the import file field delimiter

Enclosed By ' "'
If the data is closed with a certain symbol, specify 'fields enclosed by':

TERMINATED BY LINES '\ n' ( 字段列表);
field list ignores the self-energizing indexing
each data \ n divided

Import File Example

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_41049126/article/details/93716970