How to insert garbled data into MySQL

Source: Internet
Author: User

Symptom: Use JDBC to insert Chinese fields into the MySQL database, and then open the table to find that the fields are all "?? ", Or garbled.

Cause:

1. The default encoding method is not specified when you create a database. As a result, the database uses the default Character Set latin1 of MySql.

2. The Client character set is latin1.

3. Unmatched character sets are used for jdbc links.

Solution:

1. When creating a database, specify the default Character Set of the database as utf8. SQL statement not found...

2. Modify the default Character Set of the Client to utft. In windows, find my In the mysql installation directory. ini, change default-character-set = latin1 to default-character-set = UTF8, then restart the mysql service to change the default Character Set of the database to utf8. at this time, use the \ s command on the mysql command line to check whether the character set has been changed.

3. Modify the jdbc link to change the original

Jdbc: mysql: // localhost: 3306/YourDb

Change

Jdbc: mysql: // localhost: 3306/YourDb? UseUnicode = true & characterEncoding = UTF-8

After completing the above work, the Chinese characters inserted into mysql should not be garbled.

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.