MyCAT默認字符集是UTF8
下面通過查看日志來驗證不同的MySQL客戶端字符集和服務器字符集對於MyCAT的影響。
日志中與字符集有關的主要有三部分:
1. 初始化MyCAT連接池
2. 心跳檢測
3. 在執行SQL語句時的連接同步。
因為MyCAT實現的是三節點的讀寫分離和自動切換,以下修改的均是localhost節點上MySQL實例的字符集,其它兩個點(192.168.244.146和192.168.244.144)均沒有修改。默認為
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | 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/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec)
一、當客戶端字符集(character_set_client)為utf8,服務端字符集(character_set_server)為latin1。
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | 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/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
MyCAT的日志輸出如下:
1. 初始化連接池
2. 心跳檢測
3. 在執行SQL語句時的連接同步。
二、當客戶端字符集為latin1,服務端字符集也為latin1。
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | 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 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
MyCAT的日志輸出如下:
1. 初始化MyCAT連接池
2. 心跳檢測
3. 在執行SQL語句時的連接同步。
三、當客戶端字符集為latin1,服務端字符集也為utf8。
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
MyCAT的日志輸出如下:
1. 初始化MyCAT連接池
2. 心跳檢測
3. 在執行SQL語句時的連接同步。
四、當客戶端字符集為utf8,服務端字符集也為utf8。
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | 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/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
MyCAT的日志輸出如下:
1. 初始化MyCAT連接池
2. 心跳檢測
3. 在執行SQL語句時的連接同步。
總結:
初始化MyCAT連接池,心跳檢測的字符與服務端字符集有關,即character_set_server設定的值。當localhost的MySQL實例的字符集改成utf8後,因為192.168.244.146和192.168.244.144兩個節點的MySQL實例的字符集並沒有發生變化,所以執行心跳檢測時,localhost的字符集為utf8,其它兩個節點仍為latin1。
同步連接與客戶端字符集有關,即character_set_client設定的值。