Setup GTID REPLICATION MySQL 8.4

I will share you, how to make and configuration GTID Replication in MySQL 8.4. The method can be backup stand by your database server. If your primary database broken, you can using slave replication or this backup db server. Okkay, let’s see how to config GTID Replication.

  1. Stop Application service and all cronjob to databases.
  2. Create user replication di master server
  3. mysql> CREATE USER 'repuser'@'%' IDENTIFIED BY 'Password123#';
    mysql> GRANT REPLICATION SLAVE ON *.* TO 'repuser'@'%';
    mysql> FLUSH PRIVILEGES;
  4. Setup my.cnf replication master server.
  5. Check BINARY LOG STATUS.
  6. mysql> SHOW BINARY LOG STATUS;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000003 |      158 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 sec)
  7. Backup database master server.
  8. # mysqldump -u root -p --opt --routines --all-databases > alldatabases.sql
  9. Setup my.cnf replication slave server.
  10. # vi /etc/my.cnf
    =======================================================
    [mysqld]
    log_bin=/var/lib/mysql/mysql-bin.log
    relay-log=/var/lib/mysql/mysql-relay-bin.log
    server-id=2
    gtid_mode=ON
    enforce-gtid-consistency=ON
    log-replica-updates=ON
    skip-replica-start=ON
    read_only = 1
    super_read_only = 1
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    =======================================================
    # systemctl restart mysqld
    # systemctl status mysqld 
  11. Restore database master ke server slave.
  12. # mysql -u root -p < alldatabases.sql
  13. Setup GTID Replication di server SLAVE.
  14. # mysql -u root -pid
    mysql > CHANGE REPLICATION SOURCE TO \
    SOURCE_HOST='[IP_ADDRESS_MASTER_DB]',
    SOURCE_PORT=3306, \
    SOURCE_USER='repuser', \
    SOURCE_PASSWORD='Password123#', \
    SOURCE_AUTO_POSITION=1, \
    GET_SOURCE_PUBLIC_KEY=1;
    mysql> START REPLICA;
    mysql> SHOW REPLICA STATUS \G;