MySQL Chinese garbled Solution

Source: Internet
Author: User

Add or modify the following in my. CNF:Code:
[Client]
Default-character-set = utf8
[Mysqld]
Default-character-set = utf8

We recommend that the encoding on the webpage be consistent with the encoding on the database. If both are utf8, set them to utf8. If they are GBK, set them to GBK;

If the above Code is not added, even if the encoding specified during MySQL compilation and installation is utf8, the default encoding is Latin1 during database creation. Due to the inheritance of the character set, the tables in the database are also latin1.

Here are a few commands. You can try them by yourself:
1. List all character sets supported by MySQL:
Show Character Set;

2. Current MySQL Server Character Set
Show variables like 'character _ SET _ % ';

3. Current MySQL Server character set verification settings
Show variables like 'collation _ % ';

4. display character set settings of a Database
Name of the show create database;

5. display character set settings of a data table
Show create table table name;

6. Modify the database Character Set
Alter database name default Character Set 'utf8 ';

7. Modify the character set of a data table
Alter table table name default Character Set 'utf8 ';

8. Specify the character set during database creation
Create Database database name Character Set GBK collate gbk_chinese_ci;

9. Specify the character set during table Creation
Create Table 'mysqlcode '(
'Id' tinyint (255) unsigned not null auto_increment primary key,
'Content' varchar (255) not null
) Type = MyISAM Character Set GBK collate gbk_chinese_ci;

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.