MySQL latin1 encoded in Chinese to UTF8

Source: Internet
Author: User

In MySQL, the corresponding table field encoding is usually the default lartin1 encoding, in the local client when the display is garbled, but through the mysql-u-p-h command login, select query to the data is normal, through JDBC or PHP, etc. to fetch back the Chinese is garbled;

That is, Chinese in MySQL is lartin1, to our own local or with Navicat and other select is garbled, using the MySQL built-in function to convert

SELECT Convert (Unhex (hex (convert name using latin1)) using UTF8) as name from test

The above statement means that, in table test, the field name is encoded as a lartin1 query and the result is converted to UTF8 encoded result

PS (Spit groove!!!): See a lot of people also through the JDBC query when the set names Lartin1, but also the new String (rs.getstring ("Samplecolumnname"). GetBytes (" Iso-8859-1 ")," UTF-8 "), pulled a lot of, the final result is still garbled, hairy with, a MySQL built-in function is done, it is easy to understand.

MySQL latin1 encoded in Chinese to UTF8

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.