首頁 >資料庫 >mysql教程 >MySQL中文_MySQL

MySQL中文_MySQL

WBOY
WBOY原創
2016-06-01 13:45:06954瀏覽

bitsCN.com

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”
 

bitsCN.com
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn