LinuxC program inserts Chinese data garbled characters into MySQL

Source: Internet
Author: User
LinuxC program inserts Chinese data garbled into MySQL. First, read the article "Cannot display MySQL Chinese Characters in Linux and solve sock Link errors" w

Linux C Programming inserts Chinese data garbled into MySQL. First read the article "Cannot display MySQL Chinese Characters in Linux and solve sock Link errors" http: // w

Linux C Programming inserts Chinese data garbled into MySQL.

First read this article titled "Cannot display MySQL Chinese characters and solve sock Link errors in Linux ".

After the above changes, you should add this sentence before inserting data into the database in the C program:

Mysql (conn, "set names \ 'utf8 \'");

In this way, no garbled code will be generated.

Character_set_client: Character Set of the Client

Character_set_results: Result Character Set

Character_set_connection: Connection Character Set

Command for setting these three system parameters: set names 'utf8'

Functions of these three system parameters:

Information Input path: client -- connection -- server (data transmission direction from left to right)

Information output path: server -- connection -- results (data transmission direction from left to right)

Therefore, the values of these system parameters must be the same. Otherwise, data is transmitted in different encoding methods. If the encoding method is incompatible, garbled characters may occur.

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.