在centos中配置文件为:my.cnf

my.cnf在centos中的位置为:/etc/my.cnf

打开文件修改如下:vi /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
character-set-server=utf8

[mysql]
default-character-set=utf8

---------以下时间:2015年11月18日 18:55:46---------


以下为百度引用
地址:http://zhidao.baidu.com/link?url=Mu110P4ABTw7iG7rXTYvu8OJa270n1JYALnGBnnPME2RocUO5AysZtOZnjrsGqSX8xDJ4uoGzkB6eT7zUCOAPa
###修改默认字符集
1、 最简单的修改方法,就是修改mysql的my.ini文件中的字符集键值, 如 ``` default-character-set = utf8 character_set_server = utf8 ```

修改完后,重启mysql的服务,service mysql restart
使用

 mysql> SHOW VARIABLES LIKE 'character%';

查看,发现数据库编码均已改成utf8

+--------------------------+---------------------------------+ 
| Variable_name | Value | 
+--------------------------+---------------------------------+ 
| 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" | 
+--------------------------+---------------------------------+ 

2、还有一种修改字符集的方法,就是使用mysql的命令

mysql> SET character_set_client = utf8 ; 
mysql> SET character_set_connection = utf8 ; 
mysql> SET character_set_database = utf8 ; 
mysql> SET character_set_results = utf8 ; 
mysql> SET character_set_server = utf8 ; 

mysql> SET collation_connection = utf8 ; 
mysql> SET collation_database = utf8 ; 
mysql> SET collation_server = utf8 ; 

3、一般就算设置了表的默认字符集为utf8并且通过UTF-8编码发送查询,你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。解决方法是在发送查询前执行一下下面这句:

SET NAMES 'utf8'; 

它相当于下面的三句指令:

SET character_set_client = utf8; 
SET character_set_results = utf8; 
SET character_set_connection = utf8; 

补充:*
先把数据导出,把数据库转换完毕后再把数据导回数据库