At work, we need to insert and read and write Chinese data to MySQL. This problem was tricky at first. After a period of investigation, the problem was solved smoothly.
The solution is as follows:
1. Set the character set of the MySQL server. The default Character Set of the MySQL server is utf8;
2. Set the character set of a table or column. It is best to use UTF-8 and support both Chinese and English.
3. After the connection, call the int mysql_set_character_set (MySQL * MySQL, char * csname) interface. This function sets the default character set for the current connection.
Note that only MySQL 5.0.7 and later versions support this function. In earlier versions, the set names <character setname> statement can be used instead.
4. When reading and writing data to MySQL, convert all strings to utf8 encoding. The English utf8 encoding is the same as that of ANSI, and there are differences between Chinese characters.
The above is my solution, if there is a problem, please contact me <bicheng.gui@gmail.com>.
TheArticleOriginal. Please note the post!