View MySQL database server and database character set.
mysql> show variables like '%char% '; +--------------------------+----------------------- --------------+------| variable_name | Value |......+------ --------------------+-------------------------------------+------| character_set_client | utf8 | ...... -- Client Character Set | character_set_connection | utf8 |......| character_set_database | utf8 |...... -- Database Character Set | character_set_filesystem | binary |......| character_set_results | utf8 |......| character_set_server | utf8 |...... -- Server Character Set | character_set_system | utf8 |......| character_sets_dir | d:\mysql server 5.0\share\ charsets\ |......+--------------------------+-------------------------------------+------
Create a database of different character sets
The default is the Latin character set when you do not change the proofing rules
Create DATABASE Test_utf8 chanacter SET utf8_general_ci; <= UTF8 Character Set database
Create DATABASE TEST_GBK DEFAULT chanacter SET gbk_chinese_ci; <= GBK Character Set database
Cases:
1, according to the development of the program to determine the character set (recommended UTF8)
2. Specify the character set at compile time
-DDEFAULT_CHARSET=UTF8-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
The default character of the table created after that is UTF8
3. Compile without specifying a default character set or a different character set from the program
Specifying characters and creating databases
>create database Test_utf8 chanacter SET utf8_general_ci; <= UTF8 Character Set database >create db TEST_GBK DEFAULT chanacter set gbk_chinese_ci; <= GBK Character Set database
4, has created a good database has data
Modifying the character set of a database
>alter database test character set utf-8;
5. Modifying character sets through configuration files
# VI/ETC/MY.CNF
[Client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]character-set-server=utf8
Restart Service
#/etc/rc.d/init.d/mysql Restart
MySQL Character set