我正在尝试通过命令行将CSV文件加载到MySQL中,但很多值都没有出现。这是我的疑问:
LOAD DATA LOCAL INFILE '/Users/zachsmith/Dropbox/1_computer_business/2014_MSc/assignments/databases/CSCresults_no_headers.CSV' INTO TABLE Temp FIELDS TERMINATED BY ',' ENCLOSED BY '"' (Year, StudentID, Degree, CourseCode, CourseDescrip, Session, Code, Percent, Symbol, Gender, SAstatus, ForeignCountry);
以及添加的内容如下:
mysql> select * from Temp
-> ;
+------+-----------+--------+-------------+--------------------------------+--------------+------+---------+--------+--------+----------+-----------------------------+
| Year | StudentID | Degree | CourseCode | CourseDescrip | Session | Code | Percent | Symbol | Gender | SAstatus | ForeignCountry |
+------+-----------+--------+-------------+--------------------------------+--------------+------+---------+--------+--------+----------+-----------------------------+
| EB022 | CSC1015F | Computer Science 1015 | Semester One | UGRD | 83 | 1 | M | F | Tanzania
| EB022 | CSC1016S | Computer Science 1B | Semester Two | UGRD | 60 | 2- | M | F | Tanzania
| SB006 | CSC1010H | Compass I -CompScAcadAssProg | Full Year | UGRD | 48 | SF | M | F | Tanzania
| SB006 | CSC1015F | Computer Science 1015 | Semester One | UGRD | 26 | F | M | F | Tanzania
|001 | CSC6000W | PhD in Computer Science | Full Year | DOCT | 0 | | M | F | Sudan
| SB006 | CSC1010H | Compass I -CompScAcadAssProg | Full Year | UGRD | 56 | 3 | M | F | Tanzania
| SB006 | CSC1015F | Computer Science 1015 | Semester One | UGRD | 41 | F | M | F | Tanzania
|| CSC1010H | Compass I -CompScAcadAssProg | Full Year | UGRD | 64 | SP | M | C |
|| CSC3002F | Computer Science 302 | Semester One | UGRD | 70 | 2+ | M | C |
|| CSC3003S | Computer Science 303 | Semester Two | UGRD | 70 | 2+ | M | C |
|| CSC3002F | Comput
很多东西都被删除了 - 比如日期和学生ID(这是虚拟数据),甚至是第5行中一半的学位代码......
所有字段都是varchar(30),因为我只是将所有内容视为字符串。这是为什么?
我看了Excel,它拿起了所有东西
答案 0 :(得分:0)
尝试使用文本编辑器打开csv文件。如果字段确实是TERMINATED BY ',' ENCLOSED BY '"'
并且每列对应于Temp
表中的相同字段,请查看它。请注意,如果CSV字段中没有任何值,则仍应使用双引号""
括起来。