咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

linux系统下mysql编码问题解决方法

2016-03-03 16:40:31 9669次
查看当前编码情况:
mysql> show variables like \%character%;
+--------------------------+----------------------------+
| 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/ |

+--------------------------+----------------------------+

修改为utf8编码:修改/etc/my.cnf
在[client]下增加default-character-set=utf8
在[mysqld]下增加character_set_server=utf8
重新查看编码情况:
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/ |
+--------------------------+----------------------------+
如此修改后,JDBC访问不会出现乱码。
注意JSP页面编码也要写成UTF-8.

首页
最新活动
个人中心