在my.ini加入,有时不顶用
[mysqld]
default-storage-engine=MyISAM
default-character-set=utf8
default-collation=utf8_general_ci
查看字符编码
show variables like 'character%';
单个设置字符编码
SET character_set_client = utf8 ;
SET character_set_connection = utf8 ;
SET character_set_database = utf8 ;
SET character_set_results = utf8 ;
SET character_set_server = utf8 ;
SET collation_connection = utf8 ;
SET collation_database = utf8 ;
SET collation_server = utf8 ;
①我们要告诉服务器,我给你发送的数据是什么编码
character_set_client
②告诉字符集转换器,转换成什么编码
SET character_set_connection
③查询的结果用什么编码
character_set_results
如果这以上三则都为utf8,可简写为set names 'utf8';
sql语句创建数据库和表时指定编码规则
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 ;
显示当前默认规则
show collation like 'gbk%';