简体   繁体   English

用数百万行更新MySQL表

[英]update a MySQL table with Millions of rows

I need to convert ip by INET_ATON() in mysql table have millions of rows 我需要在mysql表中通过INET_ATON()转换ip,它具有数百万行

UPDATE `table` SET `ip` = INET_ATON(`ip`)

I need query to be fast and good performance 我需要查询才能快速获得良好的性能

thank's 谢谢

Well it seems you're trying to assign a numeric value to a char column. 好吧,看来您正在尝试为char列分配一个数值。 As MichaelH said, if you're going to use the numeric value more than the address value, then you should consider storing the number in that format. 正如MichaelH所说,如果您要使用的数字值多于地址值,则应考虑以该格式存储数字。

However, you can store both values to improve query performance: 但是,您可以存储两个值以提高查询性能:

CREATE TABLE t (
  address char(15),
  number  int unsigned default 0
);

INSERT INTO t (address) VALUES
('255.255.255.255'),
('0.0.0.0'),
('1.0.0.0');

update t set number = inet_aton(address);
select * from t;

This would result in: 这将导致:

+-----------------+------------+
|     ADDRESS     |   NUMBER   |
+-----------------+------------+
| 255.255.255.255 | 4294967295 |
| 0.0.0.0         |          0 |
| 1.0.0.0         |   16777216 |
+-----------------+------------+

Can you not just use the ip2long() function in PHP when passing the IP address to the database? 将IP地址传递给数据库时,您不仅可以在PHP中使用ip2long()函数吗?

And then when you want to return it, wrap the field in long2ip ? 然后,当您想返回它时,将字段包装在long2ip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM