mysql> SET character_set_client = utf8 ;
mysql> SET character_set_connection = utf8 ;
利用 mysql> SHOW VARIABLES LIKE 'character%';查看,创造数据库编码均已改成utf8
+--------------------------+---------------------------------+
| Variable_name | &#118alue |
+--------------------------+---------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\公众mysql-5.0.37\"大众share\公众charsets\"大众 |
+--------------------------+---------------------------------+
mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-----------------+
| Variable_name | &#118alue |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
或者打开mysql安装目录,里面有个my.ini文件,打开这个文件,里面有两处字符集的设置,默认是拉丁,建议你所想改的,如:utf8或gbk然后启动mysql做事,往后创建的数据库默认字符集便是ok了(重启时,打开MySQLAdministrator的Service Control进行操作就可以了。)
其余一些修正mysql编码的方法:
1.如果安装mysql的编码已不能变动,很多朋友是购买虚拟主机建立网站,无权变动MYSQL的安装编码,这一关我们可以跳过,由于只要后面的步聚精确,一样能办理乱码问题
2.修正数据库编码,如果是数据库编码禁绝确: 可以在phpmyadmin 实行如下命令: ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
以上命令便是将test数据库的编码设为utf8
3.修正表的编码:ALTER TABLE `category` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
以上命令便是将一个表category的编码改为utf8
4.修正字段的编码:
ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
以上命令便是将test表中 dd的字段编码改为utf8
---更多Java学习资料可关注微信公众年夜众号:kaigexuetang_com(长按可复制关注)