Replication in MySQL
MySQL replication is used to synchronize a database which is chosen as master into the slave machines.
Example Setup:
master : aaa.aaa.aaa.aaa
slave1 : bbb.bbb.bbb.bbb
slave2 : ccc.ccc.ccc.ccc
We modify the my.cnf file in master node such as:
server-id = 1
log-bin For the changes to take affect, mysql should be restarted.
mysql> GRANT REPLICATION SLAVE ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password'
mysql> GRANT RELOAD ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password';
mysql> GRANT SUPER,REPLICATION CLIENT ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password'; mysql> GRANT REPLICATION SLAVE ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password'
mysql> GRANT RELOAD ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password';
mysql> GRANT SUPER,REPLICATION CLIENT ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password';
We modify the my.cnf file in slave1 machine such as follows (With replicate-do-table we specify which tables to replicate):
server-id = 2
master-host =aaa.aaa.aaa.aaa
master-user = slave_user
master-password=slave_password
master-port = 3306
replicate-do-table=db.TABLE1
replicate-do-table=db.TABLE2
replicate-do-table=db.TABLE3
replicate-do-table=db.TABLE4We make the same changes in the my.cnf file on slave2
server-id = 3
master-host =aaa.aaa.aaa.aaa
master-user = slave_user
master-password=slave_password
master-port = 3306
replicate-do-table=db.TABLE1
replicate-do-table=db.TABLE2
replicate-do-table=db.TABLE3
replicate-do-table=db.TABLE4For the changes to take effect, we restart mysql processes on both slaves .
On both slaves,
mysql> load data from master
mysql> slave startYou can check slave nodes and master node whether they are working synchronized as below respectively:
On slave:
mysql> show slave status\G;
************************** 1. row **************************
Slave_IO_State: Waiting for master to send event
Master_Host: aaa.aaa.aaa.aaa
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin-log.000001
Read_Master_Log_Pos: 160158
Relay_Log_File: smlcpurgw1-relay-bin.000001
Relay_Log_Pos: 59186
Relay_Master_Log_File: bin-log.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: db.TABLE1,db.TABLE2,db.TABLE3,db.TABLE4
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 160158
Relay_Log_Space: 59186
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
1 row in set (0.00 sec)
ERROR:
No query specified
On master,
mysql> show master status;
+-----------------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-----------------------------------+------------------+
| bin-log.000001 | 160158 | | |
+-----------------------------------+------------------+
1 row in set (0.00 sec)
- 0 Comment
- Halil Demirezen
- 02 Jun 2008, 20:20
-
You must be login first or sign-up for an account to post comments.
Maybe you should look at these also:
USERBOX
CATEGORIES
MOST READ TODAY
- Redirecting tcp / udp ports with socat
- Syntax highlighting in less
- Disabling reverse dns lookups in ssh
- Passwordless sudo setup
- Users with /bin/false shell to login on vsftpd
- Using lsof utility
- Scp resume
- Enabling remote desktop on a VirtualBox Machine
- dropbear rsa key problem
- XFS Filesystem has duplicate UUID problem
LAST ADDED
- Using iPhone internet sharing over bluetooth under Linux
- Using USB sound card with amarok
- Multi-conditional search and replace (clearing a ftp trojan script example)
- Disabling ipv6 functionality
- How to convert a mp3 file
- How to choose the fastest Debian mirror
- Disabling reverse dns lookups in ssh
- Rewriting destination ip address
- Deleting A File By It's Inode Value
- Learning which libraries are used for a binary
