数据库test 表stud
id,name,age,birth
其中birth是datetime,id是自递增pk
需要导入的txt文件内容
|mike|8|12/23/2020
|tom|10|2020/12/23
难度是mike,这个格式的日期用DATE_FORMAT根本处理不了,不论你怎么更改格式都没戏,我1个多小时就扔在研究它的各种参数上了。
给结论吧,用str_to_date
我的例子的情况是假设的,真实情况,只能是mike 或者tom的一种日期格式,不会混在一起
tom的日期格式,什么都不用管也能导入成功
重点是mike的生日
use test
load data local infile “e:\test\stud_date.txt”
into table stud
fields terminated by’|’
(id,name,age, @birth)
set birth=str_to_date(@birth,’%m/%d/%Y’);
完美入库