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