Mysql Load Data 语法简介

load data infile 用户高速的向数据库中做批量

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,...)]

LOW_PRIORITY:   加载数据被延迟,直道没有其他客户端从表中读取为止
CONCURRENT:   当加载的数据正在进行的时,如果有用户请求则开启新的线程来获取数据
LOCAL: 可以用户 client->server批量操作数据,也可以进行本地server操作

示例文本文件:

aa.txt文件中的内容为:

"我爱你","20","相貌平常,经常耍流氓!哈哈"
"李奎","21","相貌平常,经常耍流氓!哈哈"
"王二米","20","相貌平常,经常耍流氓!哈哈"
"老三","24","很强"
"老四","34","XXXXX"
"老五","52","***%*¥*¥*¥*¥"
"小猫","45","中间省略。。。"
"小狗","12","就会叫"
"小妹","21","PP的很"
"小坏蛋","52","表里不一"
"上帝他爷","96","非常英俊"
"MM来了","10","。。。"
"歌颂党","20","社会主义好"
"人民好","20","的确是好"
"老高","10","学习很好"
"斜三","60","眼睛斜了"
"中华之子","100","威武的不行了"
"大米","63","我爱吃"

"苹果","15","好吃"

sql:

load data infile 'D:/aa.txt' ignore into table 表名 character set gbk fields terminated by ',' enclosed by '"' lines terminated by '\r\n' (表中的字段1,表中的字段2,表中的字段3);

例如:

load data infile 'D:/aa.txt' replace into table person character set gbk fields terminated by ',' enclosed by '"' lines terminated by '\n' (name,age,description);


看看这一句是分割的什么呢?

 Load Data InFile 'd:/ccc.txt' Into Table `test1` character set gbk FIELDS TERMINATED BY ' ' enclosed by '' escaped by '\\'  Lines Terminated By '\r\n'(name,dsad);

上边一句是分割 空格为分隔符2个字段 以回车换行为一行的内容
例如   
苹果 我爱吃
荔枝啊啊 哈哈哈,啊哈哈

例如:
 Load Data InFile 'd:/ccc.txt' replace Into Table `test1` character set gbk FIELDS TERMINATED BY ' ' enclosed by'' escaped by '\\'  Lines Terminated By '\r\n'(name,dsad); 

注意 别忘了replace 是干掉相同的数据  ,如果用ignore则会忽略相同的数据

你可能感兴趣的:(数据库,mysql,批量导入)