mysql import语句截断整数
我正在尝试将文本文件导入mysql数据库。首先,我创建了模式:mysql import语句截断整数,mysql,Mysql,我正在尝试将文本文件导入mysql数据库。首先,我创建了模式: Create table tbl_windspeed( year int, month varchar(50), speed decimal, location varchar(50)); 下面是txt文件的一部分: 2015 feb 15.7 Neumayer 2015 sep \N Neumayer 2015 nov \N Ne
Create table tbl_windspeed(
year int,
month varchar(50),
speed decimal,
location varchar(50));
下面是txt文件的一部分:
2015 feb 15.7 Neumayer
2015 sep \N Neumayer
2015 nov \N Neumayer
2015 jun 17.3 Neumayer
1976 jul \N Rothera
1976 may \N Rothera
1976 oct \N Rothera
1976 apr \N Rothera
1976 mar \N Rothera
1976 aug \N Rothera
1976 jan \N Rothera
以下是import语句和与上面相同的行:
LOAD DATA INFILE 'csv_windspeed.txt' INTO TABLE tbl_windspeed;
|015 | feb | 16 | Neumayer
|015 | sep | NULL | Neumayer
|015 | nov | NULL | Neumayer
|015 | jun | 17 | Neumayer
|76 | jul | NULL | Rothera
|76 | may | NULL | Rothera
|76 | oct | NULL | Rothera
|76 | apr | NULL | Rothera
|76 | mar | NULL | Rothera
|76 | aug | NULL | Rothera
|76 | jan | NULL | Rothera
所以有两件事:
1) 年份整数被截断了
2) 即使在表模式中指定了十进制,风速数据也不会被读取为十进制
不过,当我运行查询时,有一件事很有趣:
SELECT * FROM tbl_windspeed WHERE year = 1962
我得到这个结果:
|62 | nov | 8 | Faraday
|62 | jun | 11 | Faraday
|1962 | jul | 11 | Grytviken
|1962 | may | 7 | Grytviken
|1962 | oct | 6 | Grytviken
|1962 | apr | 7 | Grytviken
|1962 | mar | 12 | Grytviken
|1962 | aug | 7 | Grytviken
|1962 | jan | 9 | Grytviken
|1962 | dec | 8 | Grytviken
|1962 | feb | 9 | Grytviken
|1962 | sep | 9 | Grytviken
|1962 | nov | 12 | Grytviken
|1962 | jun | 9 | Grytviken
|2 | jul | 13 | Halley
|2 | may | 9 | Halley
|2 | oct | 11 | Halley
|2 | apr | 13 | Halley
|2 | mar | 11 | Halley
|2 | aug | 10 | Halley
|2 | jan | 8 | Halley
|2 | dec | 9 | Halley
|2 | feb | 11 | Halley
|2 | sep | 14 | Halley
|2 | nov | 9 | Halley
|2 | jun | 11 | Halley
| | jul | 14 | Signy
| | may | 11 | Signy
| | oct | 19 | Signy
| | apr | 15 | Signy
| | mar | 11 | Signy
| | aug | 12 | Signy
| | jan | 11 | Signy
| | dec | 11 | Signy
| | feb | 16 | Signy
| | sep | 18 | Signy
| | nov | 13 | Signy
| | jun | 16 | Signy
因此,尽管mysql意识到这些行来自1962年,但它们仍然被切断。同样,小数点也被截断了。我真的不知道这里发生了什么,如果有任何帮助,我们将不胜感激,谢谢
更新:当我在mysql中运行一个查询(获得前10个最高风速)时,结果如下:
|1988 | jun | 27.9 | Neumayer
|1997 | nov | 26.9 | Neumayer
|1981 | jul | 26.8 | Neumayer
|2002 | jun | 25.8 | Neumayer
|2006 | aug | 25.6 | Neumayer
|1989 | apr | 25.5 | Neumayer
|1995 | aug | 25.5 | Neumayer
|1981 | may | 25.4 | Neumayer
|1999 | aug | 25 | Neumayer
|8 | sep | 25 | Signy
988 jun 27.9 Neumayer
997 nov 26.9 Neumayer
981 jul 26.8 Neumayer
002 jun 25.8 Neumayer
006 aug 25.6 Neumayer
989 apr 25.5 Neumayer
995 aug 25.5 Neumayer
981 may 25.4 Neumayer
999 aug 25 Neumayer
958 sep 25 Signy
请注意,最后一行的“年份”列被截断。现在,当我运行一个C程序运行相同的精确查询时,结果如下:
|1988 | jun | 27.9 | Neumayer
|1997 | nov | 26.9 | Neumayer
|1981 | jul | 26.8 | Neumayer
|2002 | jun | 25.8 | Neumayer
|2006 | aug | 25.6 | Neumayer
|1989 | apr | 25.5 | Neumayer
|1995 | aug | 25.5 | Neumayer
|1981 | may | 25.4 | Neumayer
|1999 | aug | 25 | Neumayer
|8 | sep | 25 | Signy
988 jun 27.9 Neumayer
997 nov 26.9 Neumayer
981 jul 26.8 Neumayer
002 jun 25.8 Neumayer
006 aug 25.6 Neumayer
989 apr 25.5 Neumayer
995 aug 25.5 Neumayer
981 may 25.4 Neumayer
999 aug 25 Neumayer
958 sep 25 Signy
我想这一定和视图设置有关吧?这是相同的查询,相同的数据,但有时年份列会被截断 我找到了解决办法。我的原始.txt文件是在windows中创建的。然后我将它(通过WinSCP)导入到我的Linux机器中。我发现Linux在字符方面做了一件奇怪的事情,有时Linux和Microsoft之间的字符转换可能有点粗糙。为了验证这一理论,我在Linux中打开了一个新的vi,从原始的.txt文件中复制并粘贴了数据。然后,我使用新的vi文件将数据加载到我的表中。它成功了,没有错误 实际上,
decimal
正在四舍五入。你能把这个字段改成浮动吗?我还在想,只是把模式改成了float,它就可以工作了。不知道为什么,但你现在是1/1。你能修好年份栏吗?是的,很奇怪INT
默认值为INT(11)
但尝试给它一个显式限制-INT(5)
为什么5不是4?我尝试显式地将INT设置为INT(5),但没有任何更改