Solve the Problem of mysql Default character encoding and Chinese garbled characters

Source: Internet
Author: User
This article describes in detail how to solve the problem of mysql Default character encoding and Chinese garbled characters. For more information, see.

This article describes in detail how to solve the problem of mysql Default character encoding and Chinese garbled characters. For more information, see.

MySQL Default encoding is Latin1, does not support Chinese, so how to modify the default encoding of MySQL, the following UTF-8 as an example to explain

After mysql is started, log on to mysql as the root user
Mysql> show variables like 'character % '; # display the code
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
This is the default character encoding after installation (in the figure below, windows is similar)

It should be noted that there are many changes and there are many corresponding modification methods. The following is the simplest and most thorough method:

I. Windows
1. Stop the MySQL Service
2, in the installation directory of MySQL find my. ini, if not, copy the my-medium.ini as a my. ini
3. After opening my. ini, add default-character-set = utf8 under [client] and [mysqld], save and close
4. Start the MySQL Service

Ii. Linux
1. Stop MySQL Service (bin/mysqladmin-u root shutdown-p)
2. Find my under/etc. cnf, if not, copy the my-large.cnf under the support-files directory under the MySQL installation directory to/etc/and rename it to my. cnf
3. After opening my. cnf, modify the following, save and disable

Find the client configuration [client] and add it below
Default-character-set = utf8 default character set: utf8
Add in [mysqld]
Default-character-set = utf8 default character set: utf8
Init_connect = 'set NAMES utf8' (SET utf8 encoding for mysql connection to run utf8 for mysql database)

4. Start MySQL Service (bin/mysqld_safe &) and check the encoding display again.

Mysql> show variables like 'character % '; # display the code
+ -------------------------- + ---------------------------- +
| 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/|
+ -------------------------- + ---------------------------- +
The modified encoding is displayed (in Solaris, similar to windows)

Very simple, this change once and for all, in the future MySQL All Related default encoding is UTF-8, create a new table without setting again

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.