Home > Database > Mysql Tutorial > body text

重装数据库之后,项目出现中文乱码

WBOY
Release: 2016-06-07 15:28:39
Original
1162 people have browsed it

乱码问题的出现,根本原因就是编码没统一,既然重装数据库之前,项目是没有中文乱码的,所以问题肯定是出现在数据库的编码上。 运行mysql之后,输入以下命令 show variables like 'character%'; 笔者的查询结果如下: 其中,character_set_client 客户端编码

乱码问题的出现,根本原因就是编码没统一,既然重装数据库之前,项目是没有中文乱码的,所以问题肯定是出现在数据库的编码上。

运行mysql之后,输入以下命令

show variables like 'character%';

笔者的查询结果如下:


其中,character_set_client 客户端编码方式;
character_set_connection 建立连接使用的编码;
character_set_database 数据库的编码;
character_set_results 结果集的编码;
character_set_server 数据库服务器的编码;

只要保证以上四个采用的编码方式一样,就不会出现乱码问题。由此可见笔者的数据库果然是会出现编码问题的。。解决方法也很简单,在每个项目的数据库连接配置文件中加上这个就可以了

jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf-8
或者
jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf-8
可以根据不同的XML解析工具来选择其中一个来用。


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!