日期:2014-05-16  浏览次数:20802 次

mysql设置中文

前面我们已经说过了,mysql默认的编码是latin1,不是我们所需要的gbk,所以我们要修改成为utf8,因为若要正确显示中文繁、简、日文、韩文?使用utf8,修改方法如下:
??ALTER?DATABASE?sample?####这里修改整个数据库的编码
???????CHARACTER?SET?utf8
???????DEFAULT?CHARACTER?SET?utf8
???????COLLATE?utf8_general_ci
???????DEFAULT?COLLATE?utf8_general_ci;

当然了,你也可在在建数据库的时候指定编码,比如:

CREATE?DATABASE?sample

???????CHARACTER?SET?utf8
???????DEFAULT?CHARACTER?SET?utf8
???????COLLATE?utf8_general_ci
???????DEFAULT?COLLATE?utf8_general_ci?;

接下来要做的是打开mysql所在的目录下的my.nin

在[mysqld]段加入一下代码改成:


default-character-set=utf8

?启动mysql,输入:

执行下列语句,看看结果是不是下面的:
mysql>?show?variables?like?'%character%';
+--------------------------+-------------------------------------------+
|?Variable_name????????????|?Value?????????????????????????????????????|
+--------------------------+-------------------------------------------+
|?character_set_client?????|?latin1????????????????????????????????????|
|?character_set_connection?|?latin1????????????????????????????????????|
|?character_set_database???|?utf8??????????????????????????????????????|
|?character_set_results????|?latin1????????????????????????????????????|
|?character_set_server?????|?utf8?????????????????????????????????????????????????????????????????????????
|?character_set_system?????|?utf8??????????????????????????????????????|
|?character_sets_dir???????|?C:\MySQL\MySQL?Server?5.0\share\charsets\?|
+--------------------------+-------------------------------------------+

mysql>?show?variables?like?'%collation%';
+----------------------+-------------------+
|?Variable_name????????|?Value?????????????|
+----------------------+-------------------+
|?collation_connection?|?latin1_swedish_ci?|
|?collation_database???|?utf8_general_ci???|
|?collation_server?????|?utf8_general_ci???|
+----------------------+-------------------+

?

作者:yexin218

专家分:4070

级别:21级别:21级别:21级别:21

?会员信息

?发短消息

?所属博客