This section explains how to change which member of a single-primary group is the primary. The function used to change a group's mode can be run on any member.
Use the group_replication_set_as_primary()
function to change which member is the primary in a single-primary group. This function has no effect if issued on a member of a multi-primary group.
Only a primary member can receive data from an external source and write it to the group. If a standard source to replica replication channel is running on the existing primary member in addition to the Group Replication channels, you can only change the primary member after that replication channel is stopped.
If the group is waiting on any uncommitted transactions, the operation cannot complete until they are committed, rolled back, or terminated.
If you invoke the function on a member running a MySQL Server version from 8.0.17, and all members are running MySQL Server version 8.0.17 or higher, you can only specify a new primary member that is running the lowest MySQL Server version in the group, based on the patch version. This safeguard is applied to ensure the group maintains compatibility with new functions. If any member is running a MySQL Server version between MySQL 8.0.13 and MySQL 8.0.16, this safeguard is not enforced for the group and you can specify any new primary member, but it is recommended to select a primary that is running the lowest MySQL Server version in the group.
Pass in the server_uuid
of the member which you want to become the new primary of the group by issuing:
SELECT group_replication_set_as_primary(member_uuid);
While the action runs, you can check its progress by issuing:
SELECT event_name, work_completed, work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%";
+----------------------------------------------------------------------------------+----------------+----------------+
| event_name | work_completed | work_estimated |
+----------------------------------------------------------------------------------+----------------+----------------+
| stage/group_rpl/Primary Election: Waiting for members to turn on super_read_only | 3 | 5 |
+----------------------------------------------------------------------------------+----------------+----------------+