Master to slave replication bitnami

VM1

Create replication user.

create user 'repl'@'%' identified by 'password';

Then give him permissions to replicate all databases.

grant replication slave, replication client on *.* to 'repl'@'%';
flush privileges;

VM1 my.cnf

vim /opt/bitnami/mysql/my.cnf
[mysqld]
server-id=1
log_bin=mysql-bin
log_error=mysql-bin.err

relay-log = /opt/bitnami/mysql/data/relay-bin
relay-log-index = /opt/bitnami/mysql/data/relay-bin.index
relay-log-info-file = /opt/bitnami/mysql/data/relay-bin.info

Restart MySQL

VM1 mysqldump

Lock all databases

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
EXIT

Dump all databases

mysqldump --lock-all-tables -u root -p --all-databases > masterdump.sql

Transfer dump to VM2.

Importing a dump will change the root password.

Restart MySQL

VM1 MASTER_LOG_POS

Get the MASTER_LOG_POS:

show master status;

VM2

Create replication user.

create user 'repl'@'%' identified by 'password';

Then give him permissions to replicate all databases

grant replication slave, replication client on *.* to 'repl'@'%';
flush privileges;

Restart MySQL

Check connection

mysql -h -urepl -p

VM2 my.cnf

vim /opt/bitnami/mysql/my.cnf
[mysqld]
server-id=2
log_bin=mysql-bin
log_error=mysql-bin.err

relay-log = /opt/bitnami/mysql/data/relay-bin
relay-log-index = /opt/bitnami/mysql/data/relay-bin.index
relay-log-info-file = /opt/bitnami/mysql/data/relay-bin.info

Edit MASTER_LOG_POS.

stop slave;
CHANGE MASTER TO 
MASTER_HOST = '0.0.0.0', 
MASTER_USER = 'repl', 
MASTER_PASSWORD = 'password', 
MASTER_LOG_FILE = 'mysql-bin.000001',  
MASTER_LOG_POS = 344;

Start replication

start slave;
show slave status\G;

VM1

Unlock VM1 all databaes

SET GLOBAL read_only = OFF;
UNLOCK TABLES;

Troubleshooting

If you cloned your VM you will get a conflicting MySQL UUID error.

Advertisements