输入如下sql语句执行,并得到结果
mysql> show variables like ‘character\_set\_%‘;
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+--------+
7 rows in set (0.01 sec)
mysql> show variables like ‘collation_%‘;
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
如果2.8结果显示编码并非utf8,则需修改数据库编码。请按照以下步骤进行
执行以下命令:
service mysqld stop
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
vi /etc/my.cnf
以上命令,先停止了mysql服务,而后复制一个示例配置文件作为用户配置。
在my.cnf文件中找到“[client]”,在其下添加如下语句
default-character-set=utf8
在my.cnf文件中找到“[mysqld]”,在其下添加如下语句
character-set-server=utf8
collation-server=utf8_general_ci
init-connect=‘SET NAMES utf8‘
保存并关闭my.cnf
重启mysql,执行
service mysqld start
修改完成后,请再次执行第一步中的查询,确认修改已经成功。
本文出自 “技术成就梦想” 博客,请务必保留此出处http://pizibaidu.blog.51cto.com/1361909/1701527
原文地址:http://pizibaidu.blog.51cto.com/1361909/1701527