mysql建库时设置默认编码
GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
若是已经建好的数据库可使用:
alter database opensource default character set 'utf8';
alter table `opensource`.`t_books` character SET 'utf8';
set names 'utf8'
其实在开发web程序,用JDBC和hibernate做持久层工具时,也出现了乱码,这是因为没有在连接数据库的url中加上“
?characterEncoding=UTF-8
编码查看:
show variables like "%colla%";