Openfire solves Chinese garbled characters After MySQL database is used

Source: Internet
Author: User

Openfire is a very good IM server, and it is implemented in pure Java and has multiple platform versions. Its data storage can use a variety of databases, such as MySQL and Oracle.

In actual use, the most common problem encountered is the garbled Chinese characters after the MySQL database. This problem is very interesting, and we can see some internal mechanisms of Openfire.

The actual problem is as follows: first start the Openfire server, and then use the client or directly log on to the background to create an account, specifying some Chinese attributes for the account, such as the name. If you do not restart the server, you will never find anything wrong, because all Chinese characters are displayed normally. Next, restart Openfire and log on to the client with the created account or go to the background management terminal to view the information. All Chinese characters are changed to question marks. Log on to the database and check that all Chinese characters are question marks. This illustrates two problems:

  1. Openfire has application-layer Cache
  2. Database Encoding Problems

The solution is actually very simple. First, make sure that the database code you created for openfire is utf8. The table creation statement is as follows:

Create database openfire default character set utf8 default collate utf8_general_ci

When you have created a database, you can use:

Alter database openfire default character set utf8 default collate utf8_general_ci;

Second, when initializing the Openfire database, that is, when the Openfire server is configured for the first time, the connection string connecting to the database must be in the character encoding format and the UTF-8 encoding requirements must be added to the connection, set the connection string as follows:

Jdbc: mysql: // 127.0.0.1: 3306/openfire? UseUnicode = true & characterEncoding = utf8

If the installation is complete, you can change the configuration. Go to the Openfire installation directory and find conf/openfire. open the following xml section and modify the serverURL.

<Database>

<DefaultProvider>

<Driver> com. mysql. jdbc. Driver </driver>

<ServerURL> jdbc: mysql: // 127.0.0.1: 3306/openfire? UseUnicode = true & amp; characterEncoding = utf8 </serverURL>

Note: Because & has special meanings, the original & symbol must be escaped as & amp;

Openfire details: click here
Openfire: click here

Detailed installation process of Openfire in CentOS

Openfire server configuration notes based on Jabber/XMPP protocol in CentOS 5.4

Install Openfire on Ubuntu 12.04

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.