Solution to MySQL Chinese garbled characters in Ubuntu

Source: Internet
Author: User
1. log On As root and enter the command sudogedit/etc/mysql/my on the terminal. cnf find [client] in the open file and add default-character-set = utf8 to find [mysqld_safe]. Add default-character-set = utf8 1 below. log On As root and enter the command sudo gedit/etc/mysql/my on the terminal. cnf is in the opened file
Find the [client] and add it below
Default-character-set = utf8
Find [mysqld_safe] and add it below
Default-character-set = utf8
Find [mysqld] and add it below
Default-character-set = utf8
Init_connect = 'set NAMES utf8'
Find [mysql] and add
Default-character-set = utf8

2. Restart the mysql command to make the modification take effect.

Stop command:Sudo mysqladmin shutdown-u root-p

Enable command:Sudo/etc/init. d/mysql restart

Or:Sudo mysqld_safe-user = mysql &

3. view the current mysql Encoding
Enter the mysql command: sudo mysql-u root-p

Run the show variables like 'character % 'command to check the mysql character set ';

+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +

4. The original database and table cannot take effect, but the newly created database and table can display Chinese characters normally!

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.