This address: http://www.cnblogs.com/yhLinux/p/4036506.html
Set the relevant options in the my.cnf configuration file and change to the corresponding character set.
Set Database Encoding (sudo vi/etc/mysql/my.cnf):
[Client] default -character-set = utf8[mysqld]character-set-server = UTF8collation-server = Utf8_general_ci
Resources:
14.1.4 Character Set
5.1.4 Server System Variables
10.5, "Character Set Configuration"
10.1 Character Set Support
You can specify character sets at the server, database, table, and column level.
10.1.3 specifying Character sets and collations
10.1.3.1 Server Character Set and Collation
MySQL server has a server character set and a server collation. These can is set at server startup, the command line or in a option file and changed at runtime.
10.1.3.2 Database Character Set and Collation
Every database has a database character set and a database collation.
The character set and collation for the default database can is determined from the values of the character_set_database
and collation_database
System V Ariables. The server sets these variables whenever the default database changes. If There is no default database, the variables has the same value as the corresponding Server-level system variables, and collation_server
.
specify character settings at server startup. To select a character set and collation on server startup, use the --character-set-server
and --collation-server
options. For example, to specify the options in an option file, include these lines:
[Mysqld]character-set-server=utf8collation-server=utf8_general_ci
These settings apply Server-wide and apply as the defaults for databases created by any application, and for tables create D in those databases.
You can force client programs to use specific character set as follows:
[client]default-character-set=charset_name
This is normally unnecessary. However, when character_set_system
differs character_set_server
by or character_set_client
, and you input characters manually (as database object identifiers, column values, or both), these may is displayed incorrectly in output from the client or the output itself could be formatted INCO rrectly. In such cases, starting the MySQL client with --default-character-set=system_character_set
-that are, setting the client character set to match the system characte R set-should Fix the problem.
View Settings results
Before you change my.cnf:
Mysql>SHOW VARIABLES like '%char%'; +--------------------------+---------------------------------------------------------------+| Variable_name| Value|+--------------------------+---------------------------------------------------------------+| Character_set_client| Utf8|| Character_set_connection| Utf8|| Character_set_database| Latin1|| Character_set_filesystem|Binary|| Character_set_results| Utf8|| Character_set_server| Latin1|| Character_set_system| Utf8| | character_sets_dir | /usr/local/mysql< Span style= "color: #808080;" >-5.6. 21-linux -GLIBC2. 5-x86_64 /share/charsets/ Span style= "color: #808080;" >| +-------------------- ------+---------------------------------------------------------------+
After setting, restart the MySQL service ($ sudo services mysql restart):
Mysql>SHOW VARIABLES like '%char%'; +--------------------------+---------------------------------------------------------------+| Variable_name| Value|+--------------------------+---------------------------------------------------------------+| Character_set_client| Utf8|| Character_set_connection| Utf8|| Character_set_database| Utf8|| Character_set_filesystem|Binary|| Character_set_results| Utf8|| Character_set_server| Utf8|| Character_set_system| Utf8| | character_sets_dir | /usr/local/mysql< Span style= "color: #808080;" >-5.6. 21-linux -GLIBC2. 5-x86_64 /share/charsets/ Span style= "color: #808080;" >| +-------------------- ------+---------------------------------------------------------------+
MySQL setting character set character set