mysql 匯入csv檔案

2021-10-18 20:16:47 字數 713 閱讀 5721

linux 用 shell 指令碼 批量 匯入 csv 檔案 到 mysql 資料庫

前提: 每個csv檔案第一行為欄位名

建立的資料庫欄位名同csv 檔案的欄位名

1. 批量匯入 多個 csv 檔案

for file in ./*.csv;do mv $file tablename.csv;mysqlimport --local --fields-terminated-by="," -uusename -ppassword databasename tablename.csv;rm tablename.csv;done

(改指令碼在匯入資料的同時會刪除檔案 別忘記在匯入資料庫前備份檔案啊)

2. 匯入乙個 csv 檔案

mysql --local-infile -uusename -ppassword databasename -e "load data local infile '1.csv' into table tablename fields terminated by ',' lines terminated by '\r\n'"

(',' 和 '\r\n' 是根據你的csv 檔案決定的 第乙個是 字段分割的標誌,第二個是行分割的標誌)

(--local-infile: 沒有這個會報錯【error 1148 (42000) at line 1: the used command is not allowed with this mysql version】)

Mysql 匯入csv檔案

mysql load data infile命令可以把csv平面檔案中的資料匯入到資料庫中。linux下 load data infile home test dump ip location.csv into table ip location character set utf8 fields ...

CSV檔案匯入MySQL

1 首先看一下我本次匯入的資料,比較簡單 1 在資料庫中首先建立了乙個名為 test 的資料庫,在test資料庫下建立了乙個名為 student 的 屬性如下 column name datatype note idint 11 primary key,not null name varchar 4...

Mysql 匯入csv 檔案

mysql 匯入csv檔案 mysql預設檔案存放位址是 var lib mysql files 可修改 window 生成的csv檔案 需要lines terminated by r n 加 r linux 生成的csv檔案只需要 n 就可以 如果有中文標題 最好刪除後在用 ignore 0 如果...