You are here
Mysql Database Master Slave Replication
Basic steps for the mysql database master slave replication (Tested on ubuntu).
1. Configure one server to be a master.
2. Configure one server to be a slave.
3. Connect the slave to the master.
Configure The Master
To configure a server to act as master it needs active binary log and a unique server ID. Configuration changes will go in the file located at:
/etc/mysql/my.cnf
server-id = 1
log-bin = master-bin
log-bin-index = master-bin.index
Comment out the line bind-address = 1.27.0.0.1
#bind-address = 127.0.0.1
restart the mysql server.
Create a user for feplication
mysql> CREATE USER replication_user;
Grant some power to this user.
mysql> GRANT REPLICATION SLAVE ON *.* TO replication_user IDENTIFIED BY 'secret_password';
Configure The Slave
To configure the slave configuration changes will go in the file located at:
/etc/mysql/my.cnf
server-id = 2
log-bin = slave-relay-bin
log-bin-index = master-relay-bin.index
restart the mysql server.
Add master connection information:
mysql> CHANGE MASTER TO
->MASTER_HOST = 'master_ip_or_host',
->MASTER_PORT = 3306,
->MASTER_USER = 'replication_user',
->MASTER_ PASSWORD = 'secret_password';
Start the slave:
mysql> START SLAVE;
At this point if you create a new database or a table on master those changes will reflect on slave.