Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How MySQL stores IP values

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to store the IP value of MySQL, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Store IP value

IP values are generally stored using char or varchar, but character types are not very efficient when looking up and counting. MySQL database has built-in two IP-related functions INET_ATON () and INET_NTOA (), which can convert IP addresses and integer types. After conversion, you can use INT UNSIGNED to store IP, and the converted numbers are continuous, which improves the query performance and takes up less space.

CREATE TABLE `tb_ ip` (`IP', PRIMARY KEY id` int (10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'self-increment key', `name` varchar (100) NOT NULL COMMENT 'name', `inet_ ip` int (10) unsigned NOT NULL COMMENT 'IP', PRIMARY KEY (`increment_ id`), KEY `idx_inet_ ip` (`inet_ ip`) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ip test table' # insert data insert into `name` (`name`, `inet_ ip`) values ('wang',INET_ATON (' 192.168.0.1')), ('lisi',INET_ATON (' 192.168.0.2')); # convert select INET_ATON ('192.168.0.1'); select INET_NTOA (3232235521). These are all the contents of the article "how MySQL stores IP values". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report