我有一个名为CHINESE
的表,只有一列NAME
。
SHOW VARIABLES LIKE 'char%'
的输出是:
+--------------------------+--------------------------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.1.73-osx10.6-x86_64/share/charsets/ | +--------------------------+--------------------------------------------------------+
当我运行此查询:INSERT INTO CHINESE VALUES ('你好')
,值被插入。
但是,当我尝试执行此查询:SELECT * FROM CHINESE
时,结果是:
+------+ | NAME | +------+ | ?? | +------+
SELECT HEX(NAME) FROM CHINESE
的结果是:
+-----------+ | HEX(NAME) | +-----------+ | 3F3F | +-----------+
我犯了哪个错误?
utf8
,创建一个新的数据库和测试表,在其中插入数据,看看是否可以正常工作。我认为你已经有了UTF-8数据,但服务器正在进行转换,就好像它是Latin1一样。 - tadman