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;
作者“wingware”