Solve the Problem of garbled Chinese characters After openfire uses the MySQL database

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:

Openfire has application-layer Cache

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;

Related Article

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.