How to Setup Mysql Master Slave Replication on Centos and Redhat
Here we will see how to setup Mysql Database Replication. Mysql replication is very useful in terms of
fail over solution
- Hot Stand by Node for Fail Over
- Can be used for transparent backup
- Load balancing
Installing Mysql server:
# yum -y install mysql*
Make this server master and configure it.
# vi /etc/my.cnf
Now you have to add following configuration entries in under [mysqld] section and replace database name scripts with your database name.
Now restart Mysql Service:
# /etc/init.d/mysqld restart
Login into mysql server as root and create slave user’s and grant privileges to use for replication
Before doing this replace slave_user and with your user name and password.
Here one important thing need to do write down file (mysql-bin.000009) and position numbers, Later on this number will be use in Slave Server configuration.
Configure Slave server:
Install Mysql server on slave server
# yum install mysql-server mysql
Restart mysql service:
First step to login into mysql server as root user, here we need value’s that we got on master server.
Next go with below queries for post configuration.
mysql> SLAVE STOP; mysql> CHANGE MASTER TO MASTER_HOST='172.16.60.21', MASTER_USER='slave_user', MASTER_PASSWORD='sun123', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=197; mysql> SLVAE START;
Once everything done without any error, you can check slave status with below query,
mysql> show slave status\G
Test Mysql Replication on Master and Slave Server:
Create database on Master Mysql Server:
Verify the same on Slave server by running below command.
That’s it here is simple steps for setup mysql replication…