I think you have 2 problems.
1. AUTO_INCREMENT value
In your DDL,
genre_pk
is TINYINT. Sogenre_pk
can hold 0~255.- in end of CREATE STATEMENT,
AUTO_INCREMENT=255
- This sets initial value for
genre_pk
to 255
- This sets initial value for
2. LINES TERMINATED BY
You need to change LINES TERMINATED BY
from '\r' to '\n'
3. Summary
I've tested following SQL, and it worked well.
DDL
CREATE TABLE `genres` (
`genre_pk` tinyint(2) unsigned NOT NULL AUTO_INCREMENT,
`genre_name` varchar(90) NOT NULL,
PRIMARY KEY (`genre_pk`),
UNIQUE KEY `genre_name` (`genre_name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
LOAD DATA
LOAD DATA INFILE '/path/to/Music_All_2.csv'
INTO TABLE genres FIELDS TERMINATED BY ',' ESCAPED BY '\\'
LINES TERMINATED BY '\n' IGNORE 1 LINES (genre_name);
Reply to OP's comment
1) How to reset AUTO_INCREMENTed value
When table has data which shouldn't be deleted.
ALTER TABLE table_name AUTO_INCREMENT = n;
When existing data could be deleted. (this is what you've already tried)
TRUNCATE TABLE table_name;
2) '\n' v.s '\r'
That's weird. Generally speaking,
- '\n' for Unix system
- '\r\n' for Windows system
I never heard about '\r' for carriage return. MySQL manaul(http://dev.mysql.com/doc/refman/5.5/en/load-data.html) states that
If you have generated the text file on a Windows system, you might have to use LINES TERMINATED BY '\r\n' to read the file properly, because Windows programs typically use two characters as a line terminator. Some programs, such as WordPad, might use \r as a line terminator when writing files. To read such files, use LINES TERMINATED BY '\r'.