MySQL中 server_uuid 简介-爱代码爱编程
从MySQL 5.7开始有一个 server_uuid 的概念, MySQL启动的时候会尝试从 data_dir/auto.cnf中读取该变量,如果 data_dir/auto.cnf 不存在,那么MySQL会自动产生一个,并存放至该文件中。
示例:
JCFW1PJD:/mysqldatadir/data # cat auto.cnf
[auto]
server-uuid=b0dd0ee8-ffd9-11e9-8d1c-005056aa8c82
在MySQL集群中,每台机器的 server_uuid都是不同的。另外,GTID中也使用到了 server_uuid 作为GTID的一部分。
server_uuid是只读变量,不要尝试修改data_dir/auto.cnf,除了查看auto.cnf文件外,也可以直接查看变量值
mysql> show global variables like '%uuid';
+---------------+--------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------+
| server_uuid | b0dd0ee8-ffd9-11e9-8d1c-005056aa8c82 |
+---------------+--------------------------------------+
1 row in set (0.00 sec)
在MySQL主从架构中,主从是互相知道对方的 server_uuid 的,主可以通过 show slave hosts 来查看从库的 Slave_UUID 值:
mysql> show slave hosts \G
*************************** 1. row ***************************
Server_id: 2
Host:
Port: 3306
Master_id: 1
Slave_UUID: ed09e846-25fb-11ec-914d-005056aabf2e
1 row in set (0.00 sec)
从库可以通过 show slave status 查看主库的 Master_UUID
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
..
Master_UUID: b0dd0ee8-ffd9-11e9-8d1c-005056aa8c82
Master_Info_File: /mysqldatadir/data/master.info
..
Retrieved_Gtid_Set: b0dd0ee8-ffd9-11e9-8d1c-005056aa8c82:4
Executed_Gtid_Set: b0dd0ee8-ffd9-11e9-8d1c-005056aa8c82:1-4
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
参考资料:
MySQL :: MySQL 5.7 Reference Manual :: 16.1.6 Replication and Binary Logging Options and Variables