Rate This Document
Findability
Accuracy
Completeness
Readability

Adding a New Member to the MGR

Adding a New MySQL Pod

For details, see Adding a New MySQL Pod (mysql-4 Pod).

Initialize the new member's database.

Skip this step because the MySQL image used in this document will be checked and automatically initialized during startup.

If you use other images that are not automatically initialized, refer to the following operations to initialize them:

It is assumed that the mysql-4 pod has been added to the K8s cluster and the /data/mysql/mysql_4/mysql_arm.cnf file on the physical machine where the pod is located has been mounted to the /etc/my.cnf file in the pod. Perform the following initialization operations on the K8s primary node:

  1. Log in to the database.
    1
    kubectl exec -it mysql-4 -n ns-mysql-test -- /bin/bash
    
  2. Initialize the database.
    1
    mysqld --defaults-file=/etc/my.cnf --initialize
    
  3. Start the database.
    1
    mysqld --defaults-file=/etc/my.cnf &
    
  4. Connect to the database.
    1
    mysql -uroot -p -S /data/mysql/run/mysql.sock
    
  5. Change the password of the root user.
    alter user 'root'@'localhost' identified by "test123";
    create user 'root'@'%' identified by 'test123';
    grant all privileges on *.* to 'root'@'%';
    flush privileges;

Setting MGR Parameters

  1. Add the following parameter settings to the /data/mysql/mysql_4/mysql_arm.cnf file on the physical machine where the mysql-4 pod of member 4 is located:
    skip_log_bin
    #log-bin=mysql-bin
    ssl=0
    table_open_cache=30000
    max_connect_errors=2000
    innodb_adaptive_hash_index=0
    disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
    server_id=4 ## Each member in the group has its own server ID.
    gtid_mode=ON
    enforce_gtid_consistency=ON
    binlog_checksum=NONE
    log_bin=binlog
    log_slave_updates=ON
    binlog_format=ROW
    master_info_repository=TABLE
    relay_log_info_repository=TABLE
    transaction_write_set_extraction=XXHASH64
    plugin_load_add='group_replication.so' ## Load the engine specified by this parameter when the server is started.
    group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ## Configure the group name for group replication.
    group_replication_start_on_boot=off ## After the MySQL service is started, the engine does not automatically start. If all group members are configured, you can set this parameter to on.
    group_replication_local_address= "10.99.0.18:33061" ## Local IP address and port number. This IP address is used only to communicate with the group communication engine and cannot be used for connecting to the client. In MySQL versions later than 8.0.14, an IPv6 address can be used.
    group_replication_group_seeds= "10.99.0.15:33061,10.99.0.16:33061,10.99.0.17:33061,10.99.0.18:33061" ## IP addresses and ports of all group members
    group_replication_bootstrap_group=off ## This parameter cannot be set to on in the parameter file.
  2. Modify the group_replication_group_seeds parameter of other members in the group.
    1
    set global group_replication_group_seeds= "10.99.0.15:33061,10.99.0.16:33061,10.99.0.17:33061,10.99.0.18:33061";
    

    Modify the group_replication_group_seeds parameter in the mysql_arm.cnf file of other members by adding the new member 10.99.0.18:33061.

  3. Run the following commands on the new node to create a replication account.

    The first command indicates that none of operations in the current session are recorded in bin_log.

    SET SQL_LOG_BIN=0;     
    CREATE USER rpl_user@'%' IDENTIFIED BY '123456';
    GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
    GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
    FLUSH PRIVILEGES;
    SET SQL_LOG_BIN=1;
  4. Run the following command on the new node to set authentication information:
    CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='123456' FOR CHANNEL 'group_replication_recovery';
  5. Run the following command on the new node to check whether the group_replication plug-in is installed:
    show plugins
  6. Restart MySQL.
    shutdown;

    After you restart MySQL, the pod of mysql-4 exits and a new pod is automatically deployed. You need to log in to the MySQL database of the pod again.

  7. Start group replication.
    START GROUP_REPLICATION;
  8. Confirm the member status.
    SELECT * FROM performance_schema.replication_group_members;

    If the node is successfully added and runs in the ONLINE state, compare the data of the new node with that of the primary database.