MySQL 编码问题
-------------------------------------------------------------------------------
[引子]
修改数据库编码统一编码
[client]
password=jlh2009
default-character-set=gbk
[mysqld3310]
default-character-set=gbk #deprecated
init_connect='SET NAMES gbk'
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
-------------------------------------------------------------------------------
[]
http://dev.mysql.com/doc/refman/5.1/en/charset-configuration.html
Character Set Configuration
1、You can change the default server character set and collation with the --character-set-server and --collation-server options when you start the server.
2、You can force client programs to use specific character set as follows:
[client]
default-character-set=charset_name
http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_default-character-set
3、mysql Options
--default-character-set=charset_name
Use charset_name as the default character set for the client and connection.
A common issue that can occur when the operating system uses utf8 or another multi-byte character set is that output from the mysql client is formatted incorrectly, due to the fact that the MySQL client uses the latin1 character set by default. You can usually fix such issues by using this option to force the client to use the system character set instead.
http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
4、Connection Character Sets and Collations
A SET NAMES 'x' statement is equivalent to these three statements:
SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;
http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_character-set-server
Server Command Options
5、
--default-character-set=charset_name
Command-Line Format --default-character-set=name
-C name
Option-File Format default-character-set=name
Deprecated 5.0
Permitted Values
Type string
Use charset_name as the default character set. This option is deprecated in favor of --character-set-server. See Section 9.5, “Character Set Configuration”. --default-character-set is removed in MySQL 5.5.
6、
--character-set-server=charset_name, -C charset_name
Command-Line Format --character-set-server
Option-File Format character-set-server
Option Sets Variable Yes, character_set_server
Variable Name character_set_server
Variable Scope Global, Session
Dynamic Variable Yes
Permitted Values
Type string
Use charset_name as the default server character set. See Section 9.5, “Character Set Configuration”. If you use this option to specify a nondefault character set, you should also use --collation-server to specify the collation.
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_init_connect
7、
init_connect
Command-Line Format --init-connect=name
Option-File Format init_connect
Option Sets Variable Yes, init_connect
Variable Name init_connect
Variable Scope Global
Dynamic Variable Yes
Permitted Values
Type string
A string to be executed by the server for each client that connects. The string consists of one or more SQL statements, separated by semicolon characters. For example, each client session begins by default with autocommit mode enabled. There is no global autocommit system variable to specify that autocommit should be disabled by default, but init_connect can be used to achieve the same effect:
-------------------------------------------------------------------------------
[结论]
修改数据库编码统一编码
[client]
password=jlh2009
default-character-set=gbk
[mysqld3310]
character-set-server=gbk #需要测试
collation-server=gbk #需要测试
init_connect='SET NAMES gbk'
-------------------------------------------------------------------------------
参考地址:
http://dev.mysql.com/doc/refman/5.1/en/charset-configuration.html
http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_default-character-set
http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_character-set-server
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_init_connect
http://dev.mysql.com/doc/refman/5.1/zh/charset.html