Solve MySQL Chinese garbled characters in Ubuntu

Source: Internet
Author: User
Tags mysql command line

MySQL Chinese garbled characters (My isUbuntu LinuxSystem), read a lot of solutions on the Internet, many say that you want to modify the MySQL configuration file, so I follow the method below to modify:
Method from: http://www.cnblogs.com/flyingcloude/archive/2012/09/09/2677569.html

Modify/etc/MySQL/My. cnfsudo gedit/etc/MySQL/My. cnF in my. add the following two lines to the [client] and [mysqld] segments in the CNF file: [client] default-character-set = utf8 [mysqld] default-character-set = utf8 restart MYSQL: sudo/etc/init. d/MySQL restart check the current MySQL encoding mysql> show variables like 'character % '; + bytes + | variable_name | value | + bytes + | character_set_client | utf8 | character_set_connection | utf8 | character_set_database | utf8 | bytes | binary | utf8 | | character_set_server | utf8 | character_set_system | utf8 | character_sets_dir |/usr/share/MySQL/charsets/| + ---------------------- + bytes +

I found that after the modification, MySQL cannot be started, and many methods cannot be used. After restoring the configuration file, MySQL can be started normally! This is strange. I really don't know what's going on. After I changed the database encoding method to utf8, I still cannot. The character_set_server I found is always the Latin1 character set.
Finally, we found that character_set_server = Latin1 is okay. Back up the previous database and recreate the database. During the reconstruction, select utf8-default collation as the character set and import the data. The Chinese characters are not garbled. See:

But for existing databases, modifying the database alter database... still cannot solve the garbled problem.

In addition, it is useless to use the set command in the MySQL command line to reset the character set. After the connection is closed, the character set is changed to Latin1, which is very depressing. The setting method on the internet is as follows (I have not succeeded ):

mysql> set character_set_server=utf8;mysql> set character_set_database=utf8;

Currently, I only found this method-rebuilding the database. If you have a better method, thank you for your advice!

 

 

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.