1. 程式人生 > >匯入.csv檔案到mysql資料庫

匯入.csv檔案到mysql資料庫

首先通過如下命令獲取到mysql的secure_file_priv的值:

show variables like '%secure%'

secure_file_priv 的值是在對mysql匯入匯出csv檔案時的路徑,mysql的檔案只能匯入匯出到此路徑,我的的mysql資料庫的

secure_file_priv的值為C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/

然後執行如下命令:

load data local infile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/user.csv'

into table t_user

fields terminated by ','

optionally enclosed by '"'

-- escaped by ','

escaped by '"'

lines terminated by '\r\n'

ignore 1 lines;

20多萬條記錄很快就匯入,非常快!