MySQL CHAR() Function and UTF8 Output?

前端 未结 2 1054
暖寄归人
暖寄归人 2021-01-05 14:47
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |         


        
2条回答
  •  暖寄归人
    2021-01-05 15:40

    You are confusing UTF-8 with Unicode.

    0x00FC is the Unicode code point for ü:

    mysql> select char(0x00FC using ucs2);
    +----------------------+
    | char(0x00FC using ucs2) |
    +----------------------+
    | ü                   | 
    +----------------------+
    

    In UTF-8 encoding, 0x00FC is represented by two bytes:

    mysql> select char(0xC3BC using utf8);
    +-------------------------+
    | char(0xC3BC using utf8) |
    +-------------------------+
    | ü                      | 
    +-------------------------+
    

    UTF-8 is merely a way of encoding Unicode characters in binary form. It is meant to be space efficient, which is why ASCII characters only take a single byte, and iso-8859-1 characters such as ü only take two bytes. Some other characters take three or four bytes, but they are much less common.

提交回复
热议问题