BBBBB

mysql 文本文件导入

1:指定字段分隔符和行分隔符导入,参考地址:http://dev.mysql.com/doc/refman/5.1/en/load-data.html

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

2:定长字段导入,fixed-width

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

[REPLACE | IGNORE]
    INTO TABLE tbl_name

(@row)

 

SET colum1= TRIM(SUBSTR(@row,start,end)),
    colum2
= TRIM(SUBSTR(@row,start,end)),

 

  .....
    columN
= TRIM(SUBSTR(@row,start,end))
;  

 

posted @ 2013-04-21 15:17  如是然  阅读(250)  评论(0编辑  收藏  举报