Currently you're losing data for using BINARY(16). To insert you need to unhex the value, for example:
INSERT INTO <your-table> (IP) VALUES(UNHEX("00000000000000000000ffff5bd25452"));
To get it back you'll be required to use HEX, to have the original form back:
SELECT HEX(IP) FROM <your-table>;
Edit 1: in apropos of your comment
how can I insert an IP string such as 107.180.58.16
As IPv4 addresses are 4 byte long, same as an INT (UNSIGNED)
:
Use INET_ATON
to convert it to INT
, and INET_NTOA
to convert it back to IPv4 - for example:
INSERT INTO <your-table> (IP) VALUES (INET_ATON("107.180.58.16"));
SELECT INET_NTOA(IP) FROM <your-table>;
And, for IPv6 addresses i.e. 128 bits you can use 16 bytes binary field, BINARY(16)
or VARBINARY(16)
.