MySQL Chinese garbled problem

Source: Internet
Author: User

Although the computer installed MySQL, but has not been how to study the problem of modifying the code, usually need to use Chinese characters, are used pinyin to replace, because it is doing some simple grammar exercises, so also did not pay much attention to this issue.
My database has some garbled data table, Baidu on the internet a number of methods, such as:
mysql> set names UTF8; #修改编码为utf8
These are not used at all, the result is garbled. The other thing is to first look at the database is currently in which encoding state:
Mysql> Show variables like '%character% '; +--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | UTF8                       | | character_set_connection | UTF8                       | | character_set_database   | latin1                     | | character_set_filesystem | binary                     | | character_set_ Results |    UTF8 |                       | character_set_server     | latin1                     | | character_set_system     | UTF8                       | | Character_sets_dir       |/usr/share/mysql/charsets/|+--------------------------+----------------------------+8 Rows in Set (0.00 sec) mysql>
then use a command similar to the following, will not UTF8 encoding, and then modify into UTF8
Mysql> set Character_set_database=utf8;
It looks like this method restarts and then restores. Later see a method, is to modify the configuration file to complete, this I tried, reboot will not be restored.
First shut down the MySQL service (online is with service MySQL stop, tried, not used)
[Email protected]:~$ sudo/etc/init.d/mysql Stop
then change the configuration file
[Email protected]:~$ sudo gedit/etc/mysql/my.cnf
then add the following (do not have extra space at the end of something, I accidentally knock at the end of a space, the result is not effective):
Character_set_server=utf8  init_connect= ' Set NAMES UTF8 '

Finally open the MySQL service (online is with service MySQL start, tried, not used)

[Email protected]:~$ sudo/etc/init.d/mysql Start

So I began to build the table, the results found that the last Chinese or garbled, I looked at the syntax to build the table, found that the default encoding is not UTF8,

Then I create a new table, this time I specify the table encoding, the last Chinese part can be displayed normally.



MySQL Chinese garbled problem

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.