【发布时间】:2021-12-10 07:30:46
【问题描述】:
最近,我在从 CSV 文件导入时遇到问题。我正在使用
MariaDB : 10.3.32-MariaDB-0ubuntu0.20.04.1
On Ubuntu : Ubuntu 20.04.3 LTS
我正在使用这个命令
LOAD DATA LOCAL INFILE '/path_to_file/data.csv' INTO TABLE tab
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
搜索并尝试后,我发现我只能从 tmp 文件夹加载文件。即
SELECT load_file('/tmp/data.csv');
但它在其他路径上不起作用。
其次,我发现即使 CSV 文件存在于 tmp 文件夹中;如果它包含很多字段,那么 MariaDB 将再次无法加载。主要问题是LOAD DATA 命令没有给出任何类型的错误甚至警告;除非文件不存在。除此之外没有任何显示。并且没有导入任何内容。
我只成功地从 tmp 文件夹导入了非常简单的 CSV
我怀疑是这样的
-
MariaDB 已经更新,在这个新版本中,有一些标志或配置选项禁止 MariaDB 从 tmp 文件夹以外导入 CSV 文件和
-
MariaDB 将无法加载 CSV,因为一些未知问题,可能是一些特殊字符(我确保其中没有任何内容)。
-
必须有一些选项使 MariaDB 产生详细的错误和警告日志。我不知道。
/var/log/mysql/error.log文件除外。其中不包含任何包含未能加载 CSV 的信息。
任何帮助将不胜感激。
以下是 CSV 的第一条记录。实际 CSV 包含 49 个字段和 1862 条记录(但以下示例仅包含一条记录)
"S.No","Training Code","Intervention Type (NRM/Emp. Skill
Training)","Training Title/Activity","Start Month","Ending
Month","No. of Days Trainings","Start Date Training","End Date
Training","Name of Person","Father
Name","CNIC","Gender","Age","Education","Skill Level","CO Ref
#","COName","Village Name","Tehsil Name","District","Type of Farm
production","Total Land (if applicable)","Total Trees (if
applicable)","Sheeps/goats","Buffalo/Cows","Profession","Person's
Income Emp. Skill (Pre-Intervention)","Income from NRM (Pre-
Intervention)","HH Other Sources of Income","Total HH Income","Type
of Support provided","Tool Kit/Inputs Received or Not","Date of
Tool Kit receiving","Other intervention , like exposure market
trial, followup support, Advance Training etc","Production (Pre-
Intervention)","Production (Post-Intervention)","Change in
Production","Unit (kg, Maund,Liter, etc)","Income gain from
production (Post-Intervention)","Change in Income (NRM)","Income
gain by Employment -Emp.Skill (Post Intervention)","Change in
Income (Emp. Skill)","Outcome Trend","Employment/Self-
Employment/Other","Outcome Result","Remarks","Beneficiaries Contact
No.","Activity Location"
1,"AUP-0001","NRM","Dates Processing &
Packaging","Sep/2018","Sep/2018",2,"25/Sep/2018","26/Sep/2018",
"Some name","Barkat Gul",1234567891234,"Male",34,"Primary","Semi-
Skilled","AUP-NWD-073","MCO Haider Khel Welfare Committee","Haider
Khel","Mir Ali","North
Waziristan","Dates",,20,,,"Farming",,5000,"Farming",5000,"Training,
Packaging Boxes","Yes","10/10/2018",,180,320,140,"Kg",8000,3000,,,
"Positive","Self Employed","Value addition to the end product
(Packaging increase the Price per KG to 25%)",,,"Field NW"
【问题讨论】: