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.
- Stop Application service and all cronjob to databases.
- Create user replication di master server
- Setup my.cnf replication master server.
- Check BINARY LOG STATUS.
- Backup database master server.
- Setup my.cnf replication slave server.
- Restore database master ke server slave.
- Setup GTID Replication di server SLAVE.
mysql> CREATE USER 'repuser'@'%' IDENTIFIED BY 'Password123#';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repuser'@'%';
mysql> FLUSH PRIVILEGES;
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)
# mysqldump -u root -p --opt --routines --all-databases > alldatabases.sql
# 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
# mysql -u root -p < alldatabases.sql
# 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;