问题
设置半同步复制变量时报错
mysql> set global rpl_semi_sync_master_enabled = 0;
ERROR 1193 (HY000): Unknown system variable 'rpl_semi_sync_master_enabled'
或者
mysql> set global rpl_semi_sync_slave_enabled = 0;
ERROR 1193 (HY000): Unknown system variable 'rpl_semi_sync_slave_enabled'
这是因为没有安装半同步插件。
查看plugins,没有发现半同步复制插件。
mysql> show plugins;
+----------------------------+----------+--------------------+-----------------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+-----------------+---------+
| keyring_file | ACTIVE | KEYRING | keyring_file.so | GPL |
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
... ...
解决方案
首先,当前MySQL版本是5.7.23,已自带半同步复制插件安装包。
mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.7.23 |
+-----------+
1 row in set (0.00 sec)
安装rpl_semi_sync_master plugin
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.08 sec)
重新设置
mysql> set global rpl_semi_sync_master_enabled = 0;
Query OK, 0 rows affected (0.00 sec)
安装rpl_semi_sync_slave plugin:
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.02 sec)
重新设置:
mysql> set global rpl_semi_sync_slave_enabled = 0;
Query OK, 0 rows affected (0.00 sec)
在主库实例和从库实例上,都安装两个半同步复制插件。
因为如果发生主从切换,从库会成为主库。
查看半同步复制相关的plugins:
mysql> SELECT PLUGIN_NAME FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'rpl_semi_sync_%';
+----------------------+
| PLUGIN_NAME |
+----------------------+
| rpl_semi_sync_master |
| rpl_semi_sync_slave |
+----------------------+
2 rows in set (0.00 sec)
mysql>
可以看到,有两个半同步复制插件。