将 .csv 文件导入 MySQL 表时遇到问题。
mysql> LOAD DATA INFILE '/var/lib/mysql-files/script_output.csv'
REPLACE INTO TABLE incidents columns terminated by ',' optionally
enclosed by '"' ignore 1 lines;
ERROR 1292 (22007): Incorrect datetime value: '2021-08-29T04:18:35Z' for column 'incident_start' at row 1
但是,我可以在没有命令问题的情况下导入IGNORE
。
mysql> LOAD DATA INFILE '/var/lib/mysql-files/script_output.csv'
IGNORE INTO TABLE incidents columns terminated by ',' optionally
enclosed by '"' ignore 1 lines;
Query OK, 0 rows affected, 809 warnings (0.01 sec) Records: 266 Deleted: 0 Skipped: 266 Warnings: 809
我的要求是替换/更新列,以防表中先前值的任何更新。
表结构
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| incident | varchar(12) | NO | PRI | NULL | |
| description | varchar(300) | YES | | NULL | |
| status | varchar(12) | YES | | NULL | |
| urgency | varchar(7) | YES | | NULL | |
| service | varchar(27) | YES | | NULL | |
| trigger | varchar(25) | YES | | NULL | |
| team | varchar(20) | YES | | NULL | |
| incident_start | datetime(6) | YES | | NULL | |
| incident_end | datetime(6) | YES | | NULL | |
| resolved_by | varchar(20) | YES | | NULL | |
+----------------+--------------+------+-----+---------+-------+
在使用替换选项导入 .csv 时,我们如何解决日期时间不正确的问题?