MySQL Group Replication如何获得主节点ip地址

时间:2016-12-28 05:45:41

标签: mysql replication

根据MYSQL 5.7参考手册:

在单模式下部署组复制时,我们可以使用下面的sql查找主节点的主机名:

mysql> SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member');
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 9176f4d3-c7f6-11e6-bcf7-fa163ee40410 | myhost      |       24801 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)

问题是:如何获取IP地址而不是主机名?

2 个答案:

答案 0 :(得分:0)

您无法获取主机名的任何ipaddress。如果您要连接到某个主机,那么您就知道该主机名的ipaddress。这是mysql论坛上的mailing list,对你有所帮助。

答案 1 :(得分:0)

好的,我们可以使用名为report_host的属性指向我们的IP地址,例如:

在我自己的机器中,我部署了三个节点(s1,s2,s3)以形成一个复制组,在所有my.cnf中,定义它(10.202.7.88是我的IP地址):

report_host=10.202.7.88

然后重启所有节点并重新配置三个节点以形成复制组,然后查询:

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | 10.202.7.88 |       24801 | ONLINE       |
| group_replication_applier | 9abe6249-d321-11e6-bb5c-fa163ee40410 | 10.202.7.88 |       24802 | ONLINE       |
| group_replication_applier | a1c89c34-d321-11e6-bbbc-fa163ee40410 | 10.202.7.88 |       24803 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)

然后我们可以使用上面的sql记忆来获取主节点的ip地址:

mysql> SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member');
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | 10.202.7.88 |       24801 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)