首页 新闻 搜索 专区 学院

关于文件的批量上传到MYSQL数据库

0
[已解决问题] 解决于 2015-04-25 10:24

关于文件批量上传到Mysql数据库,(是一个试题类型的文件),给一些好的方法见解,谢谢

小屁孩asas的主页 小屁孩asas | 菜鸟二级 | 园豆:202
提问于:2015-04-24 08:35
< >
分享
最佳答案
0

要从外部文件中方便地引入数据从而创建表,MySQL提供了下面的方便方法:假定存在一个表pet,建立一个文本文件pet.txt,每一行为一个 记录,记录的每个字段用TAB分开,记录中字段一一对应,若有空字段,应使用NULL来表示,对于文本文件中,则用 \N表示。

To load the text file pet.txt into the pet table, use this statement:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

If you created the file on Windows with an editor that uses \r\n as a line terminator, you should use this statement instead:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

-> LINES TERMINATED BY '\r\n';

(On an Apple machine running OS X, you would likely want to use LINES TERMINATED BY '\r'.)

You can specify the column value separator and end of line marker explicitly in the LOAD DATA statement if you wish, but the de-

faults are tab and linefeed. These are sufficient for the statement to read the file pet.txt properly.

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'

[REPLACE | IGNORE]

INTO TABLE tbl_name

[CHARACTER SET charset_name]

[{FIELDS | COLUMNS}

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

奖励园豆:5
女孩,加油 | 小虾三级 |园豆:1098 | 2015-04-24 10:37

这是我第一次在博客园问问题,虽然没用你的方法解决,我自己解决了,但是还是特别谢谢你

小屁孩asas | 园豆:202 (菜鸟二级) | 2015-04-25 10:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册