修改mysql的编码为utf8
MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[mysqld] 和 [client]段都加入如下指令:
default-character-set=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编码了。
MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[mysqld] 和 [client]段都加入如下指令:
default-character-set=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编码了。
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2613/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表