MySQL CHAR()函数和UTF8输出? [英] MySQL CHAR() Function and UTF8 Output?

查看:394
本文介绍了MySQL CHAR()函数和UTF8输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_set_client     | utf8                                                   |
| character_set_connection | utf8                                                   |
| character_set_database   | utf8                                                   |
| character_set_filesystem | binary                                                 |
| character_set_results    | utf8                                                   |
| character_set_server     | utf8                                                   |
| character_set_system     | utf8                                                   |
| character_sets_dir       | /usr/local/mysql-5.1.41-osx10.5-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.1.41    |
+-----------+
1 row in set (0.00 sec)

mysql> select char(0x00FC);
+--------------+
| char(0x00FC) |
+--------------+
| ?            |
+--------------+
1 row in set (0.00 sec)

期望实际的utf8字符->用ü"代替?"也尝试使用char(使用utf8的0x00FC),但不行.

Expecting actual utf8 character --> " ü " instead of " ? " Tried char(0x00FC using utf8) also, but no go.

使用mysql版本5.1.41

Using mysql version 5.1.41

曾经遍布Google的人,在此上找不到任何东西. MySQL文档只是简单地说,在mysql版本5.0.14之后,期望大于255的值输出多字节.

Been allover the Google, cannot find anything on this. The MySQL docs simply say that multibyte output is expected on values greater than 255, after mysql version 5.0.14.

谢谢

推荐答案

您正在将UTF-8与Unicode混淆.

You are confusing UTF-8 with Unicode.

0x00FC是ü的 Unicode 代码点:

0x00FC is the Unicode code point for ü:

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

UTF-8 编码中,两个字节表示0x00FC /a>:

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

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

UTF-8只是一种编码二进制形式的Unicode字符的方法.这是为了节省空间,这就是为什么ASCII字符仅占用一个字节,而iso-8859-1字符(如ü)仅占用两个字节的原因.其他一些字符占用3或4个字节,但不那么常见.

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.

这篇关于MySQL CHAR()函数和UTF8输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆