日期:2014-05-16 浏览次数:20928 次
gbk_bin是二进制存储.区分大小写的
gbk_chinese_ci不区分大小写
1.服务端调整
[mysqld]
default-character-set=gbk #对MYSQL5.1版本增加这一项 --default-character-set is removed in MySQL 5.5.
default-collation=gbk_bin #对MYSQL5.1版本增加这一项
character-set-server=gbk #对MYSQL5.5版本增加这一项
collation-server=gbk_bin #对MYSQL5.5版本增加这一项
但是建立数据库时如果不指定COLLATTION,则从服务器默认继承gbk_chinese_ci
2.客户端调整
mysql>show variables like 'collation_%';#调整前
+---------------------------------------------+
|variable_name |value |
|----------------------------------------------
collation_connection |gbk_chinese_ci |
|----------------------------------------------
collation_database |gbk_bin | -->服务端调整后 (调整前为gbk_chinese_ci)
|----------------------------------------------
collation_server |gbk_bin | -->服务端调整后 (调整前为gbk_chinese_ci)
|----------------------------------------------
mysql>set names 'gbk' collate 'gbk_bin';#进行调整后,再看下面
mysql>show variables like 'collation_%';
+---------------------------------------------+
|variable_name |value |
|----------------------------------------------
collation_connection |gbk_bin |
|----------------------------------------------
collation_database |gbk_bin |
|----------------------------------------------
collation_server |gbk_bin |
|----------------------------------------------
3. 可通过命令检查表的规则
mysql>show full columns from tbz;
4. 建立数据库,表时指定规则
CREATE DATABASE IF NOT EXISTS TEST DEFAULT CHARACTER SET gbk COLLATE gbk_bin;
CREATE TABLE `tbz` (
`BZ` varchar(3) NOT NULL,
`BZMC` varchar(16) NOT NULL,
`BZBM` varchar(1) DEFAULT NULL,
`SM` varchar(20) DEFAULT NULL,
PRIMARY KEY (`BZ`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE gbk_bin ;
5. 显示当前默认规则 这个默认值怎么改呢??
mysql>show collation like 'gbk%';
+---------------------------------------------+------------------------------------------
|Collation |Charset | Id | Default | Compiled | Sortlen |
|----------------------------------------------------
|gbk_chinese_ci |gbk | 28 | YES | YES | 1 |
|gbk_bin |gbk &nb