Home > Database > Mysql Tutorial > MySQL连接中的中文乱码的解决

MySQL连接中的中文乱码的解决

WBOY
Release: 2016-06-07 16:52:53
Original
995 people have browsed it

mysql5.1.7-beta-log和mysql-connector-java-5.0.5中文乱码的解决整整弄了一个晚上,终于解决了jdbc(mysql-connector-java-5.0.5

mysql5.1.7-beta-log和mysql-connector-java-5.0.5中文乱码的解决

整整弄了一个晚上,终于解决了jdbc(mysql-connector-java-5.0.5)和mysql5.1.7通信中文乱码的问题!我的系统是linux(FC5)。在java中(eclipse环境)使用jdbc连接mysql。存储英文没问题,写(insert into)和读(select)都能正确显示,但是若其中带有中文字符就成乱码了。看了mysql5.1的中文手册没有解决,到网上查找了半天资料,最后终于成功。

我的经验是,在/etc/my.cnff文件中加上以下两行内容:

[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8


这时,mysql系统,,服务器、客户端、数据库、连接都使用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/ |
+--------------------------+----------------------------+

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template