9. 在设置 connector 连接参数是注意 host 填写在 consul 注册的服务地址,并加上 dns_srv 参数,不需要指定端口。import mysql.connector
cnx = mysql.connector.connect(user='root', password='root', database='mysql_innodb_cluster_metadata', host='router.service.consul', dns_srv=True)
cursor = cnx.cursor()
query = ("select instance_id from v2_this_instance")
cursor.execute(query)
for (instance_id) in cursor:
print("instance id: {}".format(instance_id))
cursor.close()
cnx.close()