在MySQL表中存储英文和中文字符的正确字符集是什么


What is the correct character set for storing English and Chinese characters in a MySQL table?

我试图将英文和中文存储在一个MySQL表的不同字段中。

lang1表示英语,lang2表示汉语。

对于表字符集,我尝试了UTF8_general_ci和UTF8_unicode_ci。

用于输入的Html页面也使用UTF8。但由于某种原因,汉字又变成了???。有人知道为什么会发生这种事吗?我还复制并粘贴了UTF8页面上的汉字。

编辑:输入页面的请求标题:

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

页面本身设置:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

编辑:看起来,在将字段lang2设置为utf8_general_ci之后,它正确地存储了字符。我将表和数据库排序规则设置为utf8,但错过了特定的字段。

这里是中文mysql字符集的简要说明。

  • http://www.haidongji.com/2007/10/04/character-set-and-collation-for-simplified-chinese-mysql/

  • http://dev.mysql.com/doc/refman/5.1/en/faqs-cjk.html#qandaitem-B-11-1-3

  • http://www.dodoskido.com/archives/003040-mysql-chinese-character-fix-or-how-to-make-utf8-work-for-you-pages.html

以下是中日韩的mysql字符集

+--------------------+---------------------------+
| CHARACTER_SET_NAME | DESCRIPTION               |
+--------------------+---------------------------+
| big5               | Big5 Traditional Chinese  |
| cp932              | SJIS for Windows Japanese |
| eucjpms            | UJIS for Windows Japanese |
| euckr              | EUC-KR Korean             |
| gb2312             | GB2312 Simplified Chinese |
| gbk                | GBK Simplified Chinese    |
| sjis               | Shift-JIS Japanese        |
| ujis               | EUC-JP Japanese           |
+--------------------+---------------------------+

如果使用UTF-8,请确保这是页面传递给数据库的字符集。然后可以将htmlenties()设置为utf8encode(),这样就可以说所有的东西都在使用相同的语言。

您还可以尝试将存储中文数据的字段设置为二进制的修复方法,如本文所示http://www.dodoskido.com/archives/003040-mysql-chinese-character-fix-or-how-to-make-utf8-work-for-you-pages.html