Reputation: 41
When I try to import my table named "Table.csv" to a MYSQl database using the linux console, it shows me the following message, ERROR 1265 (01000): Data truncated for column 'factor' at row 1
This is the description of the contents of the table that I had previously created:
+---------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------+------+-----+---------+-------+
| degrees | int(11) | YES | | NULL | |
| percentage | double | YES | | NULL | |
| factor | double | YES | | NULL | |
+---------------------+---------+------+-----+---------+-------+
This is how the data delimited only by commas "," is displayed as it is displayed from a plain text file:
1,0.35,1
2,0.10,3.0787
1,0.55,4.32
This is the sentence that I currently enter:
LOAD DATA INFILE '/var/lib/mysql-files/tabla.csv' INTO TABLE Student FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
In this case, there should be no problem because the table starts with the values from its header, since I have omitted the IGNORE 1 LINES statement;
I enclose the information where I check more questions:
https://dev.mysql.com/doc/refman/8.0/en/load-data.html
Upvotes: 2
Views: 1402
Reputation: 41
After verifying the way in which the data are structured and how the CSV file is stored, the sentence that should be used corresponds to:
LOAD DATA LOCAL INFILE '/var/lib/mysql-files/table.csv' INTO TABLE Student FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\ n';
Care should be taken with the type of data, its length and if it has some content, in this case all fields are filled with NULL, so they must be replaced by NOT NULL fields.
Upvotes: 2