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

MySQL中文
1. 数据库表中字段的字符集设置 。show create table TableName 或 show full columns from tableName


mysql> show create table t1;
+-------+------------------------------------
| Table | Create Table                      
+-------+------------------------------------
| t1    | CREATE TABLE `t1` (
  `id` int(11) NOT NULL,
  `c1` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)   
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+------------------------------------
1 row in set (0.00 sec)
                       
mysql> show full columns from t1;
+-------+-------------+----------------+------+-----+-
| Field | Type        | Collation      | Null | Key |
+-------+-------------+----------------+------+-----+-
| id    | int(11)     | NULL           | NO   | PRI |
| c1    | varchar(30) | gbk_chinese_ci | YES  |     |
+-------+-------------+----------------+------+-----+-
2 rows in set (0.00 sec)
mysql>



2. 当前联接系统参数  show variables like 'char%'


mysql> show variables like 'char%';
+--------------------------+----------------
| Variable_name            | Value
+--------------------------+----------------
| character_set_client     | gbk
| character_set_connection | gbk
| character_set_database   | latin1
| character_set_filesystem | binary
| character_set_results    | gbk
| character_set_server     | latin1
| character_set_system     | utf8
| character_sets_dir       | C:/Program File
+--------------------------+----------------
8 rows in set (0.00 sec)
mysql>


a. 中文,请确保 表中该字段的字符集为中文兼容:
big5     | Big5 Traditional Chinese
gb2312   | GB2312 Simplified Chinese
gbk      | GBK Simplified Chinese
utf8     | UTF-8 Unicode



b. 确保,联接参数与这个字段字符集一致,你可以用 set name 'charsetname';
比如, set name 'gbk';
这条命令会同时修改 character_set_client,character_set_connection,character_set_results
(如果你的这架MySQL中都为中文,则你可以在my.ini或my.cnf中加上或修改这个参数, 参数文件修改后需重启MySQL服务)
[mysql]
default-character-set=utf8;

参考:http://dev.mysql.com/doc/refman/5.1/zh/charset.html