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;