MySQL 加载数据本地 Infile SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16981462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load Data Local Infile SQL
提问by user1847961
I have an extract of data that is separated by using this character |
我有一个使用此字符分隔的数据提取 |
I need to load this data into a MySQL database table but I'm struggling with the lines terminated by function.
我需要将此数据加载到 MySQL 数据库表中,但我正在努力处理由函数终止的行。
Can anyone please help me identify the correct method to terminate these fields? My example data is below.
任何人都可以帮我确定终止这些字段的正确方法吗?我的示例数据如下。
I've already tried '"|"' but this doesn't work for the first and last fields.
我已经尝试过 '"|"' 但这不适用于第一个和最后一个字段。
Example:
例子:
00000000|OLD TRUCK|9|13|02|Z |Z |9999|111|99|ZZ|ZZ|ZZ|ZZ||ZZ|ZZ|99|999|2
回答by Alec.
Try something like this:
尝试这样的事情:
LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table
FIELDS TERMINATED BY '|'
LINES TERMINATED BY ',';
回答by Ranjit Kumar
This worked for me
这对我有用
LOAD DATA LOCAL INFILE 'd:/test.csv' INTO TABLE test
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';
加载数据本地文件 'd:/test.csv' INTO TABLE 测试
以“|”结尾的字段
以 '\n' 结尾的行;