当前位置:网站首页>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>
注意:由于&具有特殊含义,因此原&符号必须被转义为&
边栏推荐
- Web主机iptables防火墙安全脚本
- yolo 目标检测
- 屏幕显示技术进化史
- QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory
- MySQL billing Statistics (Part 1): MySQL installation and client dbeaver connection
- Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake
- 线下门店为什么要做新零售?
- PostgreSQL heap堆表 存储引擎实现原理
- Heartbeat 与DRBD 配置过程
- 杰理之检测灵敏度级别确定【篇】
猜你喜欢

【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline

Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"

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

项目经理是领导吗?可以批评指责成员吗?

Why must a digital transformation strategy include continuous testing?

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

How unity pulls one of multiple components

Conditional compilation

Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake

Halcon知识:盘点一下计量对象【1】
随机推荐
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
毕业季职场人
杰理之检测灵敏度级别确定【篇】
数据智能——DTCC2022!中国数据库技术大会即将开幕
Spark - 一文搞懂 Partitioner
Static classes use @resource annotation injection
信息学奥赛一本通 1362:家庭问题(family)
Why should offline stores do new retail?
Perl转换文件的编码类型
屏幕显示技术进化史
PostgreSQL heap堆表 存储引擎实现原理
Heartbeat 与DRBD 配置过程
Filebeat自定义index和fields
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
HeartBeat基于CRM使用NFS对MySQL高可用
Why must a digital transformation strategy include continuous testing?
This morning, investors began to travel collectively
DELL R720服务器安装网卡Broadcom 5720驱动
neo4j load csv 配置和使用
[iccv 2019] characteristics precise supervision of feature super resolution for small object detection