I have a MySQL (5.7.21) application database that contains IP (v4) addresses as VARBINARY(16) (I assume this length is meant to support IPv6).
I typically access this DB for maintenance purposes through phpMyAdmin.
I need to extract these IP addresses to some text format that I can handle with a script. PhpMyAdmin displays these columns in hex in query results, but exporting to file creates files that are difficult to handle in scripts or with a text editor.
I tried several variants of CAST/CONVERT but nothing seems to work (in particular casts to SIGNED or UNSIGNED yield 0).
Is there a solution? Am I overlooking something?
Edit
OK, so a solution is using:
INET_NTOA ( CONV ( HEX (varbinary_column),16,10 ) )
But it the bin-to-hex-to-decimal really necessary or is there a shorter form?
hex/conv, but for ip addresses, there is an even nicer option, have a look at SQL: Binary to IP Addresscolumn, inet_ntoa(column)givesaabbccdd , 0.0.0.0, so the question is why columns with data are seen as zero?convfirst to make it a number,inet_ntoais, as you said, just the cherry. Check the second answer (or the last code in the question (the last "edit")), it should work for your case. If you do not get the expected result for your specific data, you should add some sample data.