关于MyCAT字符集的验证
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设定的值。