Basic setup of master-slave GTID replication on MySQL 8

In this post let me introduce how to setup a basic master-slave replication with MySQL 8 database.

Software environment:

OS: Ubuntu 18

Database: MySQL 8

IP address of master machine: 192.168.1.10

IP address of slave machine: 192.168.1.11

Replication mode: GTID

First step(backup and restore):

If we want to setup a replication with currently running database, we need to backup and restore current database on slave machine. If both master and slave databases are new, we could just skip this step.

1: set database for read only on master machine:

mysql> SET @@GLOBAL.read_only = ON;

need to set it to ‘OFF’ after finished the setup.

2: backup and restore.

Second step(setup):

On master machine:

mysql> SET PERSIST server_id=1;

mysql> SET PERSIST_ONLY gtid_mode = ON;

mysql> SET PERSIST_ONLY enforce_gtid_consistency = true;

mysql> RESTART;

create user used in replication access:

mysql> CREATE USER ‘replica’@’%’ IDENTIFIED BY ‘strong_pass’ REQUIRE SSL;

security option: you could set this user only access from slave machine.

(CREATE USER ‘replica’@’192.168.1.11’ IDENTIFIED BY ‘strong_pass’ REQUIRE SSL;)

mysql> GRANT replication slave on *.* to ‘replica’@’%’;

On slave machine:

mysql> SET PERSIST server_id=2;

mysql> SET PERSIST_ONLY gtid_mode=ON;

mysql> SET PERSIST_ONLY enforce_gtid_consistency = true;

mysql> RESTART;

mysql> CHANGE MASTER TO

MASTER_HOST=’192.168.1.10′,

MASTER_PORT=3306,

MASTER_USER=’replica’,

MASTER_PASSWORD=’strong_pass’,

MASTER_AUTO_POSITION=1,

MASTER_SSL=1;

mysql> start slave;

After those steps your setup should work fine. You can simple test it by create a new database and table on master machine and insert some dummy data into it and check those database , table and data on slave machine.

And of course if you insert any data on slave database it wouldn’t be synced to master database.

Possible way to fix(restart replication process) the error occurred on slave database:

Try to skip GTID:

1: check slave status:

mysql> show slave status\G;

from this command we could know the ‘Executed_Gtid_Set’ and ‘Retrieved_Gtid_Set’;

for example we got:

Executed_Gtid_Set : 51777777-ff7f-aaaa-8989-asdf565fd65:1–54

and

Retrieved_Gtid_Set: 51777777-ff7f-aaaa-8989-asdf565fd65:5–5402

2: try to skip gtid:

mysql>stop slave;

mysql> set @@session.gtid_next=’51777777-ff7f-aaaa-8989-asdf565fd65:54′;

mysql> begin;

mysql> commit;

mysql> set gtid_next=’AUTOMATIC’;

mysql> start slave;

Try to reset:

On master database:

mysql> reset master;

On slave database:

mysql> stop slave;

mysql> reset slave;

mysql> reset master;

mysql> start slave;

Hope this is helpful for you, thanks your reading.


source : https://medium.com/@michael_w_s/basic-setup-of-master-slave-gtid-replication-on-mysql-8-8f39ea29765c

Note :

Add the following line in [mysqld] unit to enable read-only mode Server DB Slave ( Jika Server Database Slave hanya Mode Baca)

read-only = 1

Users with SUPER privilege (like root) can still write to the database, so you should be careful when granting privileges to users. If you don’t want anyone to be able to change/delete the database, you can add the following line in [mysqld] unit.

innodb-read-only = 1

Save and close the file. Then restart MariaDB for the change to take effect.

sudo systemctl restart mysql
Posted on: June 28, 2022, by :  | 101 views
https://serang.ut.ac.id/css/css/slot88/ https://tinjut.bagkeu.dikdasmen.kemdikbud.go.id/slot-maxwin/ https://dpm.polinema.ac.id/slot-gacor/ https://akademik.ft.unm.ac.id/slot-dana/ https://ppdb.probolinggokab.go.id/slot-5000/ https://bkad.sulselprov.go.id/assets/ https://ojs.balidwipa.ac.id/docs/slot-gacor/ http://korpri.pekalongankab.go.id/api/slot-gacor/ https://elang.umpp.ac.id/foto/farmasi/-/asset/ http://rsud-kelet.jatengprov.go.id/wp-content/-/asset/ https://kusdhianto-fe.staff.ugm.ac.id/slot88/ http://ppdb.probolinggokab.go.id/judi-bola/ https://bapenda.labuhanbatukab.go.id/racikan-sbobet/ http://rsud-kelet.jatengprov.go.id/wp-content/-/data/ https://agenda.riau.go.id/-/judi-bola/ https://balapan.padang.go.id/sbobet88/ http://jdih.wakatobikab.go.id/sbobet88/ http://kph.menlhk.go.id/sbobet88/ https://bkad.sulselprov.go.id/data/ https://dpm.polinema.ac.id/slot-gacor/ https://dinkes.jemberkab.go.id/storage/attachments/