(This is a response to Andrew's answer, but does not match the comment.)
WHERE __input_ip__ REGEXP concat('^', replace(ip_address, '.', '\.'))
A good plan, except that in MySQL \ is a (non-standard SQL) escape string literal, so to get it in regexp, you probably need '\\\.' !
... with the exception of ANSI mode, it is not. Argh! To be compatible, you need to get a backslash in another way:
WHERE __input_ip__ REGEXP CONCAT('^', REPLACE(ip_address, '.', CHAR(92, 46)))
Ugh. It might be better to forget the regex and do this with string ops:
WHERE LEFT(__input_ip__, CHAR_LENGTH(ip_address))=__input_ip__
source share