GLOBAL 级别继承
/* Set collactions that depends on the default collation */
global_system_variables.collation_server= default_charset_info;
global_system_variables.collation_database= default_charset_info;
if (is_supported_parser_charset(default_charset_info))
{
global_system_variables.collation_connection= default_charset_info;
global_system_variables.character_set_results= default_charset_info;
global_system_variables.character_set_client= default_charset_info;
}
else
{
sql_print_information("'%s' can not be used as client character set. "
"'%s' will be used as default client character set.",
default_charset_info->csname,
my_charset_latin1.csname);
global_system_variables.collation_connection= &my_charset_latin1;
global_system_variables.character_set_results= &my_charset_latin1;
global_system_variables.character_set_client= &my_charset_latin1;
}
static Sys_var_struct Sys_character_set_server(
"character_set_server", "The default character set",
SESSION_VAR(collation_server), NO_CMD_LINE,
offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null));
mysql> show global variables like '%char%';
+--------------------------+----------------+
| Variable_name | Value |
+--------------------------+----------------+
| character_set_client | latin1 | --继承
| character_set_connection | latin1 | --继承
| character_set_database | latin1 | --继承 建立数据库默认字符集
| character_set_filesystem | binary |
| character_set_results | latin1 | --继承
| character_set_server | latin1 | --继承来源
| character_set_system | utf8 | --内部使用UTF8比如临时表
+--------------------------+----------------+
+---------------------------+-------------------+
| Variable_name | Value |
+---------------------------+-------------------+
| collation_connection | latin1_swedish_ci | --继承
| collation_database | latin1_swedish_ci | --继承
| collation_server | latin1_swedish_ci | --继承
| protocol_version | 10 |
| slave_compressed_protocol | OFF |
+---------------------------+-------------------+
session 级别 客户端将依据OS字符集更改,set names命令也影响这几个参数:
/*
Check if the changed variable was charset. In that case we need to
update mysql->charset.
*/
if (!strncmp(data->str, "character_set_client", data->length))
is_charset= 1;
else
is_charset= 0;
export LC_ALL=zh_CN.GBK
export LANG=zh_CN.GBK
mysql> show variables like '%char%';
+--------------------------+----------------+
| Variable_name | Value |
+--------------------------+----------------+
| character_set_client | gbk | --影响
| character_set_connection | gbk | --影响
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk | --影响
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+----------------+
8 rows in set (0.00 sec)
mysql> exit
Bye
[root@mysqltest2 ~]# locale
LANG=zh_CN.GBK
LC_CTYPE="zh_CN.GBK"
LC_NUMERIC="zh_CN.GBK"
LC_TIME="zh_CN.GBK"
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=zh_CN.GBK