当前位置:网站首页>Openfire在使用MySQL数据库后的中文乱码问题解决
Openfire在使用MySQL数据库后的中文乱码问题解决
2022-06-30 19:51:00 【星哥玩云】
Openfire是一个非常不错的IM服务器,而且是纯Java实现,具有多个平台的版本,他的数据存储可以采用多种数据库,如MySQL,Oracle等。
在实际使用时大家遇到最多的就是采用MySQL数据库后的中文乱码问题,这个问题十分有趣,而且从现象上可以看出Openfire内部的一些机制。
实际问题是这样的:首先启动Openfire服务器,然后利用客户端或直接登录到后台新建一个帐户,为该帐户指定一些中文的属性,如姓名等。如果不重启服务器,你永远不会觉得有什么不对的地方,因为所有的中文显示都是正常的。接下来重启一下Openfire,再用建立的帐号登录客户端或进入后台管理端查看,会发现所有的中文全都变成了问号。登录到数据库中进行查看,发现所有的中文字符也均为问号,这说明了两个问题:
- Openfire具有应用层缓存
- 数据库编码存在问题
解决办法其实也很简单,首先要保证你为openfire创建的数据库编码是utf8的,建表语句如下:
create database openfire default character set utf8 default collate utf8_general_ci
当你原来就创建好数据库时,你可以用:
alter database openfire default character set utf8 default collate utf8_general_ci;
其次,在初始化Openfire数据库,即第一次配置Openfire服务器时,在连接数据库那里的连接串要加入字符编码格式,必须在连接里增加UTF8的编码要求,连接字符串设置如下:
jdbc:mysql://127.0.0.1:3306/openfire?useUnicode=true&characterEncoding=utf8
如果已经安装完成,这个配置也是可以改动的,直接到Openfire的安装目录下,找到conf/openfire.xml这样一个文件,打开找到如下的XML节,修改其中的serverURL即可
<database>
<defaultProvider>
<driver>com.mysql.jdbc.Driver</driver>
<serverURL>jdbc:mysql://127.0.0.1:3306/openfire?useUnicode=true&characterEncoding=utf8</serverURL>
注意:由于&具有特殊含义,因此原&符号必须被转义为&
边栏推荐
猜你喜欢

8 - 函数

The former king of fruit juice sold for 1.6 billion yuan

Lambda 表达式原理分析学习(2022.06.23)

Idle fish is hard to turn over

NLP 论文领读|文本生成模型退化怎么办?SimCTG 告诉你答案

NLP技能树学习路线-(一)路线总览

操作系统面试题汇总(不定期更新)
![Network planning | [five transport layers and six application layers] knowledge points and examples](/img/4f/31acce51b584bed5ef56b2093c4db3.png)
Network planning | [five transport layers and six application layers] knowledge points and examples

Exness: liquidity series - liquidity cleaning and reversal, decision interval

Halcon知识:盘点一下计量对象【1】
随机推荐
传输层 使用滑动窗口实现流量控制
QT :QAxObject操作Excel
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
exness:美GDP终值意外加速萎缩1.6%
Spark - 一文搞懂 Partitioner
PM这样汇报工作,老板心甘情愿给你加薪
Detailed steps for Django to upload excel tables and write data to the database
为什么一定要从DevOps走向BizDevOps?
SecureCRTPortable的安装和使用(图文详解)
Convert seconds to * * hours * * minutes
[try to hack] windows system account security
QT QStringList用法
CADD课程学习(1)-- 药物设计基础知识
What is the difference between tolocal8bit and toutf8() in QT
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
Exness: the final value of US GDP unexpectedly accelerated to shrink by 1.6%
【ICCV 2019】特征超分检测:Towards Precise Supervision of Feature Super-Resolution for Small Object Detection
Client request external interface standard processing method
神经网络入门(上)
Application of JDBC in performance test