上次说了一下C从MySql里面读取数据,这次在介绍一下如何把MySql的字符集设置为utf8
第一:查看自己MySql的字符集
mysql> show variables like 'character%';
看看是否是下面的显示:
+--------------------------+----------------------------+
| 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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
如果不是就这样改变:
mysql>SET character_set_client=utf8;
mysql>SET character_set_connection=utf8;
mysql>SET character_set_databse=utf8;
mysql>SET character_set_results=utf8;
mysql>SET character_set_server=utf8;
mysql>SET character_set_system=utf8;
mysql> show variables like 'character%';
看看是否改变过来
第二:改变一下MySql的配置文件
cd /etc/mysql/my.cnf
gedit my.cnf
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set=utf8
[mysqld]
#
# * Basic Settings
#
default-character-set=utf8
init_connect='SET NAMES utf8'
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。