MySQL and international characters in a LIKE search

01 Aug 2011 by Arthur Clemens in Code tagged MySQL, utf8

Even if your MySQL table has a unicode character set, you will run into problems when doing a LIKE search. For instance
WHERE myfield LIKE 'a%'
will also find strings that start with č.

Instead you can use a regular expression search:

WHERE myfield REGEXP '^a'

See the official MySQL regular expressions documentation.

Note that word boundary regexes are different in MySQL:

WHERE myfield REGEXP '[[:<:]]word[[:>:]]'

Comments

Leave your comment