Search code examples
mysqlunicodeliteralsunicode-literals

Unicode (hexadecimal) character literals in MySQL


Is there a way to specify Unicode character literals in MySQL?

I want to replace a Unicode character with an Ascii character, something like the following:

Update MyTbl Set MyFld = Replace(MyFld, "ẏ", "y")

But I'm using even more obscure characters which are not available in most fonts, so I want to be able to use Unicode character literals, something like

Update MyTbl Set MyFld = Replace(MyFld, "\u1e8f", "y")

This SQL statement is being invoked from a PHP script - the first form is not only unreadable, but it doesn't actually work!


Solution

  • Thanks for your suggestions, but I think the problem was further back in the system.

    There's a lot of levels to unpick, but as far as I can tell, (on this server at least) the command

    set names utf8
    

    makes the utf-8 handling work correctly, whereas

    set character set utf8
    

    doesn't.

    In my environment, these are being called from PHP using PDO, for what difference that may make.

    Thanks anyway!