把Excel資料匯入到MySQL中

2021-07-13 06:43:25 字數 732 閱讀 2000

本文**:未作修改。

開啟excel,處理好你需要的列,把不需要的列都刪掉。把標題行也刪掉,只保留資料。

另存為csv檔案。

特別注意一點:如果你的mysql預設編碼方式是utf-8的話需要用editplus等軟體把csv檔案另存為utf-8編碼格式,因為excel預設編碼格式是ansi,mysql在匯入中文資料的時候很可能會出warning:1366 incorrect string value

然後到mysql裡建表,欄位的順序要跟excel裡的完全一致。(不要建其他任何列,包括id)

然後執行如下語句:

load data local infile '[你的csv檔案路徑]' into table [表名] fields terminated by ',';

例如:load data local infile 'e:\\dev\\a.csv' into table t1 fields terminated by ',';

注意csv檔案的分隔符是逗號,所以最後terminated by之後跟的是逗號。如果是製表符,則用

例如:load data local infile 'e:\\dev\\a.csv' into table t1 fields terminated by '\t';

這一步記得檢視log,必須沒有warning才算成功。

最後alter table,加入id列(primary key,not null, auto increment)和其他列即可。

如何把excel資料匯入到mysql資料庫中

最近做的工作涉及到把excel資料匯入到mysql資料庫中,看來一些mysqlimport,phpmyadmin命令,但是不怎麼會用.就決定自己寫指令碼解決.先把excel資料檔案儲存成csv格式的檔案,然後寫了下面的簡單perl指令碼倒入mysql資料庫中.需要注意用你的mysql資料庫表的結構替...

如何把excel資料匯入到mysql資料庫中

最近做的工作涉及到把excel資料匯入到mysql資料庫中,看來一些mysqlimport,phpmyadmin命令,但是不怎麼會用.就決定自己寫指令碼解決.先把excel資料檔案儲存成csv格式的檔案,然後寫了下面的簡單perl指令碼倒入mysql資料庫中.需要注意用你的mysql資料庫表的結構替...

如何把excel資料匯入到mysql資料庫中

如何把excel資料匯入到mysql資料庫中 最近做的工作涉及到把excel資料匯入到mysql資料庫中,看來一些mysqlimport,phpmyadmin命令,但是不怎麼會用.就決定自己寫指令碼解決.先把excel資料檔案儲存成csv格式的檔案,然後寫了下面的簡單perl指令碼倒入mysql資料...