linux下:
mysql version:Ver 14.14 Distrib 5.1.41
1.)
vi /etc/my.cnf,在[mysqld]下加入default-character-set = utf8,[client]下加入default-character-set = utf8
:wq保存退出
2.)run mysql cmd, mysql->service mysql restart
3).修改MYSQL数据库编码,如果是MYSQL数据库编码不正确: 可以在MYSQL执行如下命令: ALTER DATABASE`test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
以上命令就是将MYSQL的test数据库的编码设为utf8
4).修改MYSQL表的编码:ALTER TABLE `category` DEFAULT CHARACTER SET utf8COLLATE utf8_bin 以上命令就是将一个表category的编码改为utf8
5).修改字段的编码:<br>ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SETutf8 COLLATE utf8_bin NOT NULL 以上命令就是将MYSQL数据库test表中 dd的字段编码改为utf8
关于数据库的设置可以通过phpadmin进行设置管理
6)run
show variables like 'character_set%' ;
mysql>show variables like '%char%';
+----------------------+---------------------
| Variable_name | Value
+-----------------------+---------------------
| character_set_client | gb2312
| character_set_connection | gb2312
| character_set_database | gb2312
| character_set_filesystem | binary
| character_set_results | gb2312
| character_set_server | gb2312
| character_set_system | utf8
| character_sets_dir | /usr/share/mysql/charsets/
+---------------------+----------------------
0