How MySQL stores IP values
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!