mysql在初始安装后默认编码为Latin1, 不支持中文,要把编码修改为gbk或者utf8才可以。
登录mysql后使用命令 >show variables like 'character%'; 查看当前编码格式:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
修改编码步骤:
1、使用命令service mysqld stop 或者/etc/init.d/mysql start (stop) 停止mysql
2、修改mysql配置文件my.conf, 一般位置在/etc下;找到客户端配置[client] 在下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8
init_connect='SET NAMES utf8' (设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行)
3、重启mysql即可
http://www.kisscup.cn/article/3916