我正在尝试通过bash命令行将一个较大的csv文件导入mysql。
mysql -u root --password=password -e \
"CREATE DATABASE library; \
USE library; \
CREATE TABLE books (id INT NOT NULL, \
id2 INT NOT NULL, \
id3 INT NOT NULL, \
name VARCHAR(200) NOT NULL,PRIMARY KEY (id)); \
LOAD DATA LOCAL INFILE 'books.csv' \
INTO TABLE books FIELDS TERMINATED by '\t' \
ENCLOSED BY '\'' LINES TERMINATED BY '\n' IGNORE 1 LINES \
(id,id2,id3,name)"
这是csv文件 (这只是原始文件超过600行的csv文件的一部分)
+----+-----+-----+----------------------
| id | id3 | id4 | name
+----+-----+-----+----------------------
| 2 | 3 | 4 | harry potter
| 1 | 9 | 5 | spiderwicks
| 4 | 7 | 6 | attack on titan
| 5 | 2 | 1 | the roots
| 3 | 8 | 1 | wrecking ball
| 6 | 4 | 1 | luther vandross
当我在bash终端中运行上面的sql命令时,我没有收到任何错误。但是,没有正确填充所有列。当我用SELECT * FROM books;
检查表的内容时,这就是我得到的:
+----+-----+-----+------+
| id | id3 | id4 | name |
+----+-----+-----+------+
| 2 | 0 | 0 | |
| 1 | 0 | 0 | |
| 4 | 0 | 0 | |
| 5 | 0 | 0 | |
| 3 | 0 | 0 | |
| 6 | 0 | 0 | |
id3和id4列的值为0,列名甚至没有任何值。
有人知道我在做什么错吗?