一、通过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 ;
二、通过MySQL文件修改编码方式
1、在mysql的安装目录下找到my.ini文件(如果没有的话就把my-medium.ini复制,然后重命名为my.ini即可)
2、在my.ini文件中找到[client]和[mysqld]字段,在下面均加上default-character-set=utf8,保存并关闭
[mysql]
default-character-set = utf8
[client]
default-character-set = utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
三、查看系统的字符集和排序方式的设定可以通过下面的两条命令:
SHOW VARIABLES LIKE 'character%';
SHOW VARIABLES LIKE 'collation_%';
四、重启mysql服务:
net stop mysql
net start mysql
【默认编码 default-character-set=utf8 也可改为 default-character-set=gbk 】