I need to convert ip by INET_ATON() in mysql table have millions of rows
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. 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.
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?
And then when you want to return it, wrap the field in long2ip
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.