时间:2021-07-01 10:21:17 帮助过:30人阅读
MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[client]下面加入
MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[client]下面加入如下指令:
default-character-set=utf8
[mysqld]下面加上如下指令:
default-character-set=utf8init_connect='SET NAMES utf8'
注意:如果没有[client]段,,就手工加入[client]段。然后重新启动MySQL即可。验证一下是否生效:
mysql> show variables like 'char%'
+--------------------------+----------------------------+
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>
这样新建立的数据库缺省就是UTF8编码了。