当前位置:网站首页>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>
注意:由于&具有特殊含义,因此原&符号必须被转义为&
边栏推荐
- Cv+deep learning network architecture pytoch recurrence series basenets (backbones) (I)
- MySQL billing Statistics (Part 1): MySQL installation and client dbeaver connection
- CV+Deep Learning——网络架构Pytorch复现系列——basenets(BackBones)(一)
- Taiwan SSS Xinchuang sss1700 replaces cmedia cm6533 24bit 96KHz USB audio codec chip
- 线下门店为什么要做新零售?
- 【NLP】【TextCNN】 文本分类
- exness:美GDP终值意外加速萎缩1.6%
- Character class of regular series
- neo4j load csv 配置和使用
- Ten percent of the time, the tar command can't parse the English bracket "()" when decompressing the file
猜你喜欢

消灭Bug,开发者不可不知的几款Bug探索测试神器。

Exness: the final value of US GDP unexpectedly accelerated to shrink by 1.6%

【450. 删除二叉搜索树中的节点】

Unity 如何拖拉多个组件中的一个

计网 | 【五 传输层、六 应用层】知识点及例题

“更福特、更中国”拨云见日,长安福特王牌产品订单过万

What is the difference between tolocal8bit and toutf8() in QT
![[try to hack] windows system account security](/img/2b/e6e999313e3ae4e1cbf4bfa02daef0.png)
[try to hack] windows system account security

CADD course learning (1) -- basic knowledge of drug design
Application of JDBC in performance test
随机推荐
项目经理是领导吗?可以批评指责成员吗?
NLP 论文领读|文本生成模型退化怎么办?SimCTG 告诉你答案
Data intelligence - dtcc2022! China database technology conference is about to open
广州炒股开户选择手机办理安全吗?
c语言数组截取,C# 字符串按数组截取方法(C/S)
Why must we move from Devops to bizdevops?
matlab Delaunay 三角剖分内的查询点
C language: hashtable
Application of JDBC in performance test
如何快速通过PMP考试?
杰理之关于长按开机检测抬起问题【篇】
The former king of fruit juice sold for 1.6 billion yuan
Spark - 一文搞懂 Partitioner
[iccv 2019] characteristics precise supervision of feature super resolution for small object detection
discuz 论坛提速之删除data/log下的xxx.php文件
RP prototype resource sharing - shopping app
Summary of operating system interview questions (updated from time to time)
计网 | 【五 传输层、六 应用层】知识点及例题
qt中toLocal8Bit和toUtf8()有什么区别
yolo 目标检测