數據庫讀取文件

數據庫讀取文件

create table city(
id int primary key auto_increment,
num1 int,
num2 int,
num3 int);
load data infile 'D:\city.csv' into table city
fields terminated by','
lines terminated by'\r\n'
(num1,num2,num3);
上面是指定字段了,不指定第一條則爲id

如果想不指定字段,默認使用第一條爲id,那麼創建表的時候,就不可以指定主鍵自增和多餘字段

reate table city(
id int primary key,
num1 int,
num2 int);

否則報錯

ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
ERROR 1261 (01000):Row 1 doesn't contain data for all colums

如果報錯

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec

那就是沒配置好
找到mysql57下的my.ini
第131行,設置爲
secure-file-priv=""
設置爲空代表所有地方都有讀取權限
如果是設置爲路徑,則是指定地方可以讀取
NULL則所有地方都不可以讀取

如果找不到文件路徑,可能是你的路徑含有點、空格、轉義字符,儘量避免

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章