almost from mariadb
http://teguhth.blogspot.com/2023/06/enabling-gtids-replication-in-mariadb.html
A. Configure GTID Replica MySQL 8
1. install mysql8 on server01 & server02
http://teguhth.blogspot.com/2023/07/how-to-install-mysql-8-on-centos-7.html
2. configure in server01 & restart mysql
server_id = 1 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
[root@teguhth01 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#.........
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/lib/mysql/mysql_error.log
pid-file=/var/run/mysqld/mysqld.pid
server_id = 1 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
default_authentication_plugin=mysql_native_password
[root@teguhth01 ~]#
[root@teguhth01 ~]# systemctl restart mysqld
[root@teguhth01 ~]#
3. configure in server02 & restart mysql
server_id = 2 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
[root@teguhth02 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#..........
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/lib/mysql/mysql_error.log
pid-file=/var/run/mysqld/mysqld.pid
server_id = 2 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
default_authentication_plugin=mysql_native_password
[root@teguhth02 ~]#
[root@teguhth02 ~]# systemctl restart mysqld
[root@teguhth02 ~]#
4. create user replica for server01 and for server02<optional cause mirroring >
CREATE USER 'replica'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'replica'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
5. check master status
reset master;
show master status;
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth01 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> reset master;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 157 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
6. check reset slave
reset slave all;
show slave status \G;
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth02 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> reset slave all;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show slave status \G;
Empty set, 1 warning (0.00 sec)
ERROR:
No query specified
mysql>
6. backup all database on server01
mysqldump -h teguhth01 -uroot -proot -CfQq --max-allowed-packet=1G --hex-blob --order-by-primary --set-gtid-purged=OFF --single-transaction --routines=true --triggers=true --no-data=false --all-databases > alldbdb.sql;
[root@teguhth02 data]# mysqldump -h teguhth01 -uroot -p -CfQq --max-allowed-packet=1G --hex-blob --order-by-primary --set-gtid-purged=OFF --single-transaction --routines=true --triggers=true --no-data=false --all-databases > alldbdb.sql;
WARNING: --compress is deprecated and will be removed in a future version. Use --compression-algorithms instead.
Enter password:
[root@teguhth02 data]#
[root@teguhth02 data]# ls
alldbdb.sql fullall.sh fullbackupsimple.sh mysql80-community-release-el7-7.noarch.rpm simplerestore.sh
7. restore to server02
mysql -uroot -p -f < alldbdb.sql
[root@teguhth02 data]# mysql -uroot -p -f < alldbdb.sql
Enter password:
[root@teguhth02 data]#
8. configure set master to master on server02
select @@hostname,@@version;
stop slave ; reset slave; reset master;
CHANGE MASTER TO MASTER_HOST='10.10.10.61',MASTER_PORT=3306 ,MASTER_USER='root', MASTER_PASSWORD='root', MASTER_AUTO_POSITION = 1;
start slave;
show slave status \G;
mysql> stop slave ; reset slave; reset master;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> CHANGE MASTER TO MASTER_HOST='10.10.10.61',MASTER_PORT=3306 ,MASTER_USER='root', MASTER_PASSWORD='root', MASTER_AUTO_POSITION = 1;
Query OK, 0 rows affected, 8 warnings (0.01 sec)
ERROR:
No query specified
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql>
9. check slave status
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.10.10.61
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 157
Relay_Log_File: teguhth02-relay-bin.000002
Relay_Log_Pos: 373
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 157
Relay_Log_Space: 587
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: caac348b-542a-11ee-90ef-000c2944671d
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
ERROR:
No query specified
mysql>
10. check master status before event
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth01 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 157 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| abcdef |
| information_schema |
| mysql |
| performance_schema |
| secretdb |
| sys |
| xxx |
+--------------------+
7 rows in set (0.02 sec)
mysql>
B. testing
1. check from server02 & server02 before testing
select @@hostname,@@version;
show databases;
use teguhth;
show tables;
select * from teguhth.barang;
2. create database, create tavle & insert table barang on server01
create database teguhth;
use teguhth;
create table barang(KODE_BARANG char(6) not null ,NAMA_BARANG varchar(25),SATUAN_BARANG varchar(20),STOK_BARANG decimal(4),primary key (KODE_BARANG));
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-01','RICE COOKER','BUAH',20);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-02','LEMARI ES','UNIT',8);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-03','TELEVISI','UNIT',30);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-04','RADIO/TAPE','BUAH',35);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-05','KOMPUTER','UNIT',28);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-06','KIPAS ANGIN','BUAH',38);
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
4. check from server01 & server02 after testing
select @@hostname,@@version;
show databases;
use teguhth;
show tables;
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
http://teguhth.blogspot.com/2023/06/enabling-gtids-replication-in-mariadb.html
A. Configure GTID Replica MySQL 8
1. install mysql8 on server01 & server02
http://teguhth.blogspot.com/2023/07/how-to-install-mysql-8-on-centos-7.html
2. configure in server01 & restart mysql
server_id = 1 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
[root@teguhth01 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#.........
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/lib/mysql/mysql_error.log
pid-file=/var/run/mysqld/mysqld.pid
server_id = 1 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
default_authentication_plugin=mysql_native_password
[root@teguhth01 ~]#
[root@teguhth01 ~]# systemctl restart mysqld
[root@teguhth01 ~]#
3. configure in server02 & restart mysql
server_id = 2 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
[root@teguhth02 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#..........
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/lib/mysql/mysql_error.log
pid-file=/var/run/mysqld/mysqld.pid
server_id = 2 # Unique ID for the primary server
log-bin = mysql-bin # Binary log file name prefix
binlog_format = mixed # Mixed format allows GTIDs
gtid_mode = ON # Enable GTID mode
enforce_gtid_consistency = true
slave-skip-errors=1062,1032
default_authentication_plugin=mysql_native_password
[root@teguhth02 ~]#
[root@teguhth02 ~]# systemctl restart mysqld
[root@teguhth02 ~]#
4. create user replica for server01 and for server02<optional cause mirroring >
CREATE USER 'replica'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'replica'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
5. check master status
reset master;
show master status;
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth01 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> reset master;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 157 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
6. check reset slave
reset slave all;
show slave status \G;
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth02 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> reset slave all;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show slave status \G;
Empty set, 1 warning (0.00 sec)
ERROR:
No query specified
mysql>
6. backup all database on server01
mysqldump -h teguhth01 -uroot -proot -CfQq --max-allowed-packet=1G --hex-blob --order-by-primary --set-gtid-purged=OFF --single-transaction --routines=true --triggers=true --no-data=false --all-databases > alldbdb.sql;
[root@teguhth02 data]# mysqldump -h teguhth01 -uroot -p -CfQq --max-allowed-packet=1G --hex-blob --order-by-primary --set-gtid-purged=OFF --single-transaction --routines=true --triggers=true --no-data=false --all-databases > alldbdb.sql;
WARNING: --compress is deprecated and will be removed in a future version. Use --compression-algorithms instead.
Enter password:
[root@teguhth02 data]#
[root@teguhth02 data]# ls
alldbdb.sql fullall.sh fullbackupsimple.sh mysql80-community-release-el7-7.noarch.rpm simplerestore.sh
7. restore to server02
mysql -uroot -p -f < alldbdb.sql
[root@teguhth02 data]# mysql -uroot -p -f < alldbdb.sql
Enter password:
[root@teguhth02 data]#
8. configure set master to master on server02
select @@hostname,@@version;
stop slave ; reset slave; reset master;
CHANGE MASTER TO MASTER_HOST='10.10.10.61',MASTER_PORT=3306 ,MASTER_USER='root', MASTER_PASSWORD='root', MASTER_AUTO_POSITION = 1;
start slave;
show slave status \G;
mysql> stop slave ; reset slave; reset master;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> CHANGE MASTER TO MASTER_HOST='10.10.10.61',MASTER_PORT=3306 ,MASTER_USER='root', MASTER_PASSWORD='root', MASTER_AUTO_POSITION = 1;
Query OK, 0 rows affected, 8 warnings (0.01 sec)
ERROR:
No query specified
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql>
9. check slave status
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.10.10.61
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 157
Relay_Log_File: teguhth02-relay-bin.000002
Relay_Log_Pos: 373
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 157
Relay_Log_Space: 587
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: caac348b-542a-11ee-90ef-000c2944671d
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
ERROR:
No query specified
mysql>
10. check master status before event
mysql> select @@hostname,@@version;
+------------+-----------+
| @@hostname | @@version |
+------------+-----------+
| teguhth01 | 8.0.34 |
+------------+-----------+
1 row in set (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 157 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| abcdef |
| information_schema |
| mysql |
| performance_schema |
| secretdb |
| sys |
| xxx |
+--------------------+
7 rows in set (0.02 sec)
mysql>
B. testing
1. check from server02 & server02 before testing
select @@hostname,@@version;
show databases;
use teguhth;
show tables;
select * from teguhth.barang;
2. create database, create tavle & insert table barang on server01
create database teguhth;
use teguhth;
create table barang(KODE_BARANG char(6) not null ,NAMA_BARANG varchar(25),SATUAN_BARANG varchar(20),STOK_BARANG decimal(4),primary key (KODE_BARANG));
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-01','RICE COOKER','BUAH',20);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-02','LEMARI ES','UNIT',8);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-03','TELEVISI','UNIT',30);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-04','RADIO/TAPE','BUAH',35);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-05','KOMPUTER','UNIT',28);
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-06','KIPAS ANGIN','BUAH',38);
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
4. check from server01 & server02 after testing
select @@hostname,@@version;
show databases;
use teguhth;
show tables;
select @@hostname,@@version,KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG from barang;
No comments:
Post a Comment