Mysql
 SQL >> Database >  >> RDS >> Mysql

Caricare dati di tipo date in MySQL con LOAD DATA

La stringa di formato passata a STR_TO_DATE() non è valida. Nelle tue date le ore sono in formato 24 ore (%H o %k) e non 12 ore (%h). Puoi vedere tutti i specificatori di formato qui.

Cambia

%d-%b-%y %h:%i:%s

in

%d-%b-%y %H:%i:%s

Il comando diventerà simile a:

LOAD DATA INFILE '/path/to/temp_test.csv'
IGNORE INTO TABLE temp_test
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES (@c1, c2)
SET c1 = STR_TO_DATE(@c1, '%d-%b-%y %H:%i:%s');

Dopo il caricamento con i dati di esempio:

mysql> select * from temp_test;
+---------------------+------+
| c1                  | c2   |
+---------------------+------+
| 2012-06-07 22:50:19 | abc  |
| 2013-06-07 22:50:19 | bcd  |
+---------------------+------+
2 rows in set (0.00 sec)