1. 程式人生 > >在mysql中,excel文件數據的導出和導入

在mysql中,excel文件數據的導出和導入

outfile post IT expr 根目錄 excel文件 priority ted file

數據的導出:

select * from mytable into outfile ‘d:/mytable.xls‘;

你就可以在盤根目錄下,發現mytable.xls文件

數據的導入:

用導出的表mytable.xls導入:輸入命令:load data infile ‘d:/mytable.xls‘ into table mytable;

註釋:mytable :是數據庫的表名

當數據庫中的表有主鍵和自增字段時,會報錯,數據無法添加,解決方案:

  1. 把mytable.xls表中的自增並且主鍵的那一列刪除掉
  2. 輸入命令:load data infile ‘d:/mytable.xls‘ into table mytable(name,count)
    ;即可。數據是追加進去的,不是覆蓋
  3. 自增字段 :auto_increment,主鍵:primary_key
  4. 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 | ROWS}] [(col_name_or_user_var [, col_name_or_user_var] ...)] [SET col_name={expr | DEFAULT}, [, col_name={expr | DEFAULT}
    ] ...]

在mysql中,excel文件數據的導出和導入