Modify and view MySQL character sets
1. About MySQL Character Set
MySQL Character Set Support has two aspects:
Character set and Collation ).
MySQL supports character sets in four layers: server, database, table, and connection ).
MySQL can refine the character set designation to a database, a table, and a column.
2. View MySQL Character Set
2. 1. View Character Set settings
Mysql> show variables like 'character _ set _ % ';
2. View Character Set sorting settings
Mysql> show variables like 'collation _ % ';
3. Modify the MySQL Character Set
3.1 modify server-level Character Set
A. Temporary Modification
Mysql> set global character_set_server = utf8;
B. Permanent modification
Open/etc/mysql/my. cnf and add character-set-server = utf8 after [mysqld ].
3.2 modify Database level
A. Temporary changes
Mysql> set global character_set_database = utf8;
B. Permanent modification
You can change the server level.
3.3 Modify Table-level
Mysql> alter table table_name default charset utf8; it takes effect permanently after modification
3.4 Column-level modification example
Mysql> alter table 'products' CHANGE 'products _ model' VARCHAR (20) character set utf8 COLLATE utf8_general_ci null default null; it takes effect permanently after modification
3.5 change the connection Character Set
A. Temporary changes: mysql> set global character_set_client;
B. permanent change: Open/etc/mysql/my. cnf and add default-character-set = utf8 after [client ].
How to view and change the character set used by MySQL in C Language
Finally, I figured out the character set used by MySQL. MySQL provides the interface function prototype: void STDCALL mysql_get_character_set_info (MYSQL * mysql, MY_CHARSET_INFO * charset). The MY_CHARSET_INFO struct is defined as follows: typedef struct character_set {unsigned int number; /* character set number */unsigned int state;/* character set state */const char * csname;/* collation name */const char * name; /* character set name */const char * comment;/* comment */const char * dir;/* character set Directory */unsigned int mbminlen;/* min. length for multibyte strings */unsigned int mbmaxlen;/* max. length for multibyte strings */} MY_CHARSET_INFO; call the preceding function and print the result: MY_CHARSET_INFO charset; mysql_get_character_set_info (mysql, & charset); printf. number); printf (character set state: % d \ n, charset. state); printf (collation name: % s \ n, charset. csname); printf (character set n Ame: % s \ n, charset. name); printf (comment: % s \ n, charset. comment); printf (character set directory: % s \ n, charset. dir); printf (min. length for multibyte strings: % d \ n, charset. mbminlen); MySQL provides the interface function prototype: int STDCALL mysql_set_character_set (MYSQL * mysql, const char * csname); 0 is returned for success and non-0 is returned for failure.
Mysql changes the default Character Set
Let's take a look at my picture to answer the question. I won't be able to answer the question for a hundred times when I submit the answer.