从CSV导入14位时间戳到MySQL,避免剥离数据 [英] Importing 14 digit timestamp from CSV to MySQL and avoid stripping out data

查看:335
本文介绍了从CSV导入14位时间戳到MySQL,避免剥离数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个mySQL数据库,该数据库将包含其数据时间戳.这些时间戳将从一个如下所示的CSV文件中导入-20110701083231

I'm creating a mySQL db that will contain as part of its data, timestamps. These timestamps will be imported from a CSV file in which they appear like this - 20110701083231

我的问题是将这些数据存储为的最佳数据类型是什么?

My question is which is the best datatype to store these as?

到目前为止,在我的尝试中,在导入过程中(我通过PHPMyAdmin执行),时间戳记的末尾似乎被剥夺了,它们变为2011070000000.

In my attempts so far, during the import process (which I am doing via PHPMyAdmin) the end of the timestamp appears to get stripped out and they become 2011070000000.

奇怪的是,当我返回CSV文件时,那里的条目似乎也以相同的方式被剥夺了??

Oddly, when I return to the CSV file, the entries there also appeared to be stripped out in the same way...?

在此感谢您所散发出的光芒以及以前给予的所有帮助.

Thanks in advance for any light you shed and for all previous help given.

推荐答案

尝试使用此语句吗?

LOAD DATA INFILE 'yourFile.csv'
INTO TABLE yourTable
(@var1)
SET theColumnWhereItShouldBe = STR_TO_DATE(@var1, '%Y%m%d%H%i%s');

哦,该列的类型应该为datetimetimestamp.

Oh, and the column should be of type datetime or timestamp.

这篇关于从CSV导入14位时间戳到MySQL,避免剥离数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆