Notice: article written based on Ubuntu system
1. About the MySQL character set
MySQL Character set support (Character set supports) has two aspects:
The character set (Character set) and the Sort method (Collation).
MySQL support for character sets is refined to four levels: server, database, data table (table), and connection (connection).
MySQL Specifies the character set that can be refined to a database, a table, a column, and what character sets should be used.
2. View the MySQL character set 2.1. View settings for a character set
Mysql> Show variables like ' character_set_% ';
2.2. View character set sorting settings
Mysql> Show variables like ' collation_% ';
3. Modifying the MySQL character set 3.1 modifying the server-level character set
A. Temporary modifications
Mysql>set GLOBAL Character_set_server=utf8;
B. Permanent modification
Open/etc/mysql/my.cnf, add Character-set-server=utf8 after [mysqld]
3.2 Modifying the database level
A. Temporary changes
Mysql>set GLOBAL Character_set_database=utf8;
B. Permanent changes
You can change the server level.
3.3 Modifying table-level
Mysql>alter TABLE table_name DEFAULT CHARSET UTF8; Changed after permanent effect
3.4 Modifying a column-level modification example
Mysql>alter TABLE ' products ' change ' Products_model ' VARCHAR (CHARACTER SET UTF8 COLLATE utf8_general_ci NULL DEFA ULT NULL; Changed after permanent effect
3.5 Changing the connection character set
A. Temporary change:mysql> SET GLOBAL character_set_client;
B. Permanent change: open/etc/mysql/my.cnf, add Default-character-set=utf8 after [client]
notice:3.1 and 3.5 need to restart Mysql:service mysql restart
Settings for the MySQL character set