Oracle & MySQL Support

InfraStack-Labs Oracle & MySQL DBA Services help you manage, maintain, and optimize your critical Oracle systems. We deliver 24/7, year-round support with flexible monthly contracts that don’t lock you in.

Please contact me :- ajith.narayanan@infrastack-labs.in

Tuesday, May 17, 2016

MySQL Database Replication Setup

MASTER - Omegha-erp
SLAVE      - Omegha-bcp
Database Version -   MySQL 5.5

In the MASTER server


1. Enable binary logging

root@Omegha-erp:~#sudo vi /etc/mysql/my.cnf
---
[mysqld]
#log-bin=mysql-bin
log-bin=/var/log/mysql/mysql-bin.log
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
---
root@Omegha-erp:~#sudo /etc/init.d/mysql restart

2. Creation replication user account on the source database

mysql> CREATE USER 'repl'@'%' IDENTIFIED BY '*****';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

3. Take backup and note the position for slave replication

mysql> flush tables with read lock;
mysql> show master status ;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      330 |              |                  |
+------------------+----------+--------------+------------------+

$ sudo mysqldump -uroot -p*** --all-databases --master-data > dbdump.db

unlock tables;


In the SLAVE server

4. Set unique server id

root@Omegha-bcp:~#sudo vi /etc/mysql/my.cnf
---
server-id               = 2
---
root@Omegha-bcp:~#sudo /etc/init.d/mysql restart

5. Transfer backup file from the Master to Slave server

root@Omegha-bcp:~#scp -i ~/.ssh/pub-key.pem ubuntu@xx.xx.xx.xx:dbdump.db .

6. Import data

root@Omegha-bcp:~#mysql -uroot -p*** < dbdump.db

7. Point to master

mysql> change master to master_host='xx.xx.xx.xx', master_user='repl', master_password='****', master_log_file='mysql-bin.000001', master_log_pos=330;
mysql> start slave;
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: xx.xx.xx.xx
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 267
               Relay_Log_File: mysqld-relay-bin.000004
                Relay_Log_Pos: 413
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 267
              Relay_Log_Space: 716
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
1 row in set (0.01 sec)

mysql>




HAPPY LEARNING!

No comments:

Post a Comment

Thanks for you valuable comments !