Chinese write database garbled and incorrect string value: ' \xf0\x9f ... ' for column ' XXX ' at row 1 resolved

Source: Internet
Author: User
Tags character set table name

1. Chinese Writing garbled problem:

I entered the Chinese code is Urf8, built library is Urf8, but inserted MySQL is always garbled, a bunch of "???????????????????????"

I used the Ibatis, finally found the reason, I was so resolved:

The original URL address is: jdbc:mysql://localhost:3306/comment1

Instead: Jdbc:mysql://localhost:3306/comment1?? Useunicode=true&characterencoding=utf-8

It's OK.

2.Incorrect string value: ' \xf0\x9f ' for column ' XXX ' at row 1

The problem, because the UTF-8 encoding could be two, three, four bytes. Emoji emoticons or some special characters are 4 bytes, and MySQL UTF8 encode up to 3 bytes, so data is not plugged in.

That's my solution.

1. Locate the My.ini in the MySQL installation directory and make the following changes:

[Mysqld]

Character-set-server=utf8mb4

[MySQL]

Default-character-set=utf8mb4

Restart MySQL after modification convert the already built tables to UTF8MB4

Command: ALTER TABLE table_name convert to Character set UTF8MB4 collate utf8mb4_bin; (Replace table_name with your table name)

And then it's OK. A version of the online spread adds a step that will character_set_client,character_set_connection,character_set_database,character_ the MySQL environment variable Set_results,character_set_server all changed into UTF8MB4.

But I did not do this step, also normal, so may be this step is superfluous.

Reference article:

http://blog.csdn.net/likendsl/article/details/7530979

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.