MySQL修改字符集编码

通过修改字符集编码为utf8,彻底解决中文问题。

一. 登录MySQL查看SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下:

+--------------------------+----------------------------+
| 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 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

character_set_database和character_set_server的默认字符集还是latin1。

二. 修改mysql的my.cnf文件中的字符集键值

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect=’SET NAMES utf8′
character-set-server = utf8

或者直接命令行修改:

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

重启mysql服务即可。

注意:命令行修改只对当前状态有效,重启失效。彻底解决请修改文件。


参考###

上一篇:如何优雅的进入IT世界


下一篇:AI技术说:人工智能相关概念与发展简史