Mysql Master Slave Replication



                      MySQL Master Slave Replication




MASTER SIDE
=========================================================
# vim /etc/my.cnf  (add below )
=========================================================
server-id               = 1
log_bin                 = /var/lib/mysql/mysql-bin.log
binlog_do_db            = DB_NAME (if you need all databases then no need this parameter) 
===================================================================================
# service mysqld restart
===================================================================================
LOGIN IN MASTER DATABASE
===================================================================================
# mysql -u root -pXXXXXXX 
mysql> create database DB_NAME;
mysql> use mysql;
mysql> GRANT REPLICATION SLAVE ON *.* TO 'UserName'@'%' IDENTIFIED BY 'Password';

mysql> FLUSH PRIVILEGES;
===================================================================================
flush iptables and save, also permissive selinux, and take dump of mysql
===================================================================================
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      107 | DB_NAME      |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
 
# mysqldump -u root -pXXXXX --single-transaction --flush-logs --hex-blob --master-data=2 -A > /tmp/alldump.sql
 
# head /tmp/alldump.sql -n80 | grep "MASTER_LOG_POS" 
 
====================================================================================





SLAVE SIDE 
(restore dump of mysql)
# mysql -u root -pXXXX < /tmp/alldump.sql
====================================================================================
# vim /etc/my.cnf (add below )
====================================================================================
server-id               = 2
relay-log               = /var/lib/mysql/mysql-relay-bin.log
log_bin                 = /var/lib/mysql/mysql-bin.log
binlog_do_db            = DB_NAME
====================================================================================
# service mysqld restart
====================================================================================
# mysql -u root -pXXXXXXX

mysql> CHANGE MASTER TO MASTER_HOST='MASTER_SERVER_IP',MASTER_USER='UserName', 
MASTER_PASSWORD='Password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;

mysql> start slave;

mysql>show slave status\G
===================================================================================

Comments

Post a Comment

Popular posts from this blog

PCS Corosync Pacemaker Cluster Mariadb using NFS

How to install and configure node js and PM2 in rhel7

How to Create or Configure iSCSI Server and Clinet