mariadb 在mysql中找不到正确的数据类型

vlf7wbxs  于 2022-11-08  发布在  Mysql
关注(0)|答案(1)|浏览(141)

在问我的问题之前,我必须说我是一个mysql的乞丐。
我有一个网络流量的csv文件,具有以下结构,我想存储在MariaDB中:

No.","Time","Source","Destination","Protocol","Length","Info"
"1","0.000000","192.168.1.254","192.168.1.83","TCP","66","2259  >  34951 [ACK] Seq=1 Ack=1 Win=509 Len=0 TSval=3722246587 TSecr=1268347869"
"2","0.000001","192.168.1.254","192.168.1.83","TCP","70","2259  >  34951 [PSH, ACK] Seq=1 Ack=1 Win=509 Len=4 TSval=3722246588 TSecr=1268347869"
"3","0.000013","192.168.1.83","192.168.1.254","TCP","66","34951  >  2259 [ACK] Seq=1 Ack=5 Win=502 Len=0 TSval=1268347874 TSecr=3722246588"
"4","0.000572","192.168.1.83","192.168.1.254","TCP","87","34951  >  2259 [PSH, ACK] Seq=1 Ack=5 Win=502 Len=21 TSval=1268347875 TSecr=3722246588"
"5","0.000709","192.168.1.83","192.168.1.254","TCP","68","34951  >  2259 [FIN, PSH, ACK] Seq=22 Ack=5 Win=502 Len=2 TSval=1268347875 TSecr=3722246588"
"6","0.001151","192.168.1.83","192.168.1.254","TCP","74","56341  >  2259 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=1268347876 TSecr=0 WS=128"
"7","0.011318","192.168.1.254","192.168.1.83","TCP","66","2259  >  34951 [ACK] Seq=5 Ack=22 Win=509 Len=0 TSval=3722246593 TSecr=1268347875"
"8","0.011319","192.168.1.254","192.168.1.83","TCP","74","2259  >  56341 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=3722246593 TSecr=1268347876 WS=128"
"9","0.011319","192.168.1.254","192.168.1.83","TCP","66","2259  >  34951 [FIN, ACK] Seq=5 Ack=25 Win=509 Len=0 TSval=3722246594 TSecr=1268347875"
"10","0.011343","192.168.1.83","192.168.1.254","TCP","66","56341  >  2259 [ACK] Seq=1 Ack=1 Win=64256 Len=0 TSval=1268347886 TSecr=3722246593"

为了知道列的数据类型,我运行了df.info(),结果如下:


# Column       Non-Null Count  Dtype

---  ------       --------------  -----  
 0   No.          6887 non-null   int64  
 1   Time         6887 non-null   float64
 2   Source       6887 non-null   object 
 3   Destination  6887 non-null   object 
 4   Protocol     6887 non-null   object 
 5   Length       6887 non-null   int64  
 6   Info         6887 non-null   object

因此,我使用以下代码将数据存储在一个名为table_prueba的表中:

CREATE TABLE table_prueba (
    -> id BIGINT,
    -> Time FLOAT,
    -> IP_source JSON,
    -> IP_destination JSON,
    -> Protocol  JSON,
    -> Length BIGINT,
    -> Info JSON,
    -> PRIMARY KEY (id)
    -> );

然后,使用以下命令将csv文件存储在此表中:

LOAD DATA LOCAL INFILE 'Desktop/Honeypot/Prueba.csv'
    -> INTO TABLE table_prueba
    -> FIELDS TERMINATED BY ','
    -> LINES TERMINATED BY '\r\n'
    -> IGNORE 1 LINES
    -> (id,Time, IP_source, IP_destination,Protocol,Length,Info);

但出现以下错误:

+---------+------+-----------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                 |
+---------+------+-----------------------------------------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: '"1"' for column `Prueba`.`table_prueba`.`id` at row 1         |
| Warning | 1366 | Incorrect double value: '"0.000000"' for column `Prueba`.`table_prueba`.`Time` at row 1 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 1    |
| Warning | 1366 | Incorrect integer value: '"2"' for column `Prueba`.`table_prueba`.`id` at row 2         |
| Warning | 1366 | Incorrect double value: '"0.000001"' for column `Prueba`.`table_prueba`.`Time` at row 2 |
| Warning | 1366 | Incorrect integer value: '"70"' for column `Prueba`.`table_prueba`.`Length` at row 2    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"3"' for column `Prueba`.`table_prueba`.`id` at row 2         |
| Warning | 1366 | Incorrect double value: '"0.000013"' for column `Prueba`.`table_prueba`.`Time` at row 2 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 2    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"4"' for column `Prueba`.`table_prueba`.`id` at row 3         |
| Warning | 1366 | Incorrect double value: '"0.000572"' for column `Prueba`.`table_prueba`.`Time` at row 3 |
| Warning | 1366 | Incorrect integer value: '"87"' for column `Prueba`.`table_prueba`.`Length` at row 3    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"5"' for column `Prueba`.`table_prueba`.`id` at row 3         |
| Warning | 1366 | Incorrect double value: '"0.000709"' for column `Prueba`.`table_prueba`.`Time` at row 3 |
| Warning | 1366 | Incorrect integer value: '"68"' for column `Prueba`.`table_prueba`.`Length` at row 3    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"6"' for column `Prueba`.`table_prueba`.`id` at row 3         |
| Warning | 1366 | Incorrect double value: '"0.001151"' for column `Prueba`.`table_prueba`.`Time` at row 3 |
| Warning | 1366 | Incorrect integer value: '"74"' for column `Prueba`.`table_prueba`.`Length` at row 3    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"7"' for column `Prueba`.`table_prueba`.`id` at row 4         |
| Warning | 1366 | Incorrect double value: '"0.011318"' for column `Prueba`.`table_prueba`.`Time` at row 4 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 4    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"8"' for column `Prueba`.`table_prueba`.`id` at row 5         |
| Warning | 1366 | Incorrect double value: '"0.011319"' for column `Prueba`.`table_prueba`.`Time` at row 5 |
| Warning | 1366 | Incorrect integer value: '"74"' for column `Prueba`.`table_prueba`.`Length` at row 5    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"9"' for column `Prueba`.`table_prueba`.`id` at row 5         |
| Warning | 1366 | Incorrect double value: '"0.011319"' for column `Prueba`.`table_prueba`.`Time` at row 5 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 5    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"10"' for column `Prueba`.`table_prueba`.`id` at row 5        |
| Warning | 1366 | Incorrect double value: '"0.011343"' for column `Prueba`.`table_prueba`.`Time` at row 5 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 5    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"11"' for column `Prueba`.`table_prueba`.`id` at row 6        |
| Warning | 1366 | Incorrect double value: '"0.011423"' for column `Prueba`.`table_prueba`.`Time` at row 6 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 6    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"12"' for column `Prueba`.`table_prueba`.`id` at row 7        |
| Warning | 1366 | Incorrect double value: '"0.011900"' for column `Prueba`.`table_prueba`.`Time` at row 7 |
| Warning | 1366 | Incorrect integer value: '"80"' for column `Prueba`.`table_prueba`.`Length` at row 7    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"13"' for column `Prueba`.`table_prueba`.`id` at row 7        |
| Warning | 1366 | Incorrect double value: '"0.019983"' for column `Prueba`.`table_prueba`.`Time` at row 7 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 7    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"14"' for column `Prueba`.`table_prueba`.`id` at row 8        |
| Warning | 1366 | Incorrect double value: '"0.019984"' for column `Prueba`.`table_prueba`.`Time` at row 8 |
| Warning | 1366 | Incorrect integer value: '"70"' for column `Prueba`.`table_prueba`.`Length` at row 8    |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"15"' for column `Prueba`.`table_prueba`.`id` at row 8        |
| Warning | 1366 | Incorrect double value: '"0.019996"' for column `Prueba`.`table_prueba`.`Time` at row 8 |
| Warning | 1366 | Incorrect integer value: '"66"' for column `Prueba`.`table_prueba`.`Length` at row 8    |
| Warning | 1062 | Duplicate entry '0' for key 'PRIMARY'                                                   |
| Warning | 1366 | Incorrect integer value: '"16"' for column `Prueba`.`table_prueba`.`id` at row 9        |
| Warning | 1366 | Incorrect double value: '"0.020773"' for column `Prueba`.`table_prueba`.`Time` at row 9 |
| Warning | 1366 | Incorrect integer value: '"110"' for column `Prueba`.`table_prueba`.`Length` at row 9   |
| Warning | 4025 | CONSTRAINT `table_prueba.Info` failed for `Prueba`.`table_prueba`                       |
| Warning | 1366 | Incorrect integer value: '"17"' for column `Prueba`.`table_prueba`.`id` at row 9

我真的很感谢您的帮助,因为虽然我已经尝试在表的定义中使用多种数据类型,但我无法找到正确的数据类型。

k7fdbhmy

k7fdbhmy1#

对于time,您可能希望使用DOUBLE,否则较大的值将舍入到大约7个有效数字(对于FLOAT)。
这些字符串不是“JSON”;使用VARCHAR(100)(或某个合适最大透镜)。
IP地址应该是VARCHAR(39)以处理IPv4和IPv6。但是,如果您要测试它们是否为“="以外的任何值,请这样说。将IP地址存储为字符串不能用于范围测试。

相关问题