Linux 下mysql乱码

 

问题:

 

Linux 下mysql乱码

 

 

查找原因:

mysql>show variables like '%char%';

回车后显示:

+----------------------+---------------------
| Variable_name | Value
+-----------------------+---------------------
| character_set_client | latin1
| character_set_connection | latin1
| character_set_database | latin1
| character_set_filesystem | binary
| character_set_results | latin1
| character_set_server | latin1
| character_set_system | utf8
| character_sets_dir | /usr/share/mysql/charsets/
+---------------------+----------------------

 

解决方式:

vi /etc/my.cnf

分别在如下几项中添加字符集:
[client]
default-character-set=gb2312
[mysqld_safe]
default-character-set=gb2312
[mysqld]
default-character-set=gb2312
#default-table-type=innodb
[mysql]
default-character-set=gb2312
 

 

 

再重启mysql让配置生效:

mysql>show variables like '%char%';

 

Linux 下mysql乱码

 

 

重新插入,错误依旧

Linux 下mysql乱码

 

再思考---从表结构考虑

原有

Linux 下mysql乱码

修改后

Linux 下mysql乱码

 

成功:

 

Linux 下mysql乱码

 

你可能感兴趣的:(mysql,linux)