在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%';