Environment:
Master: ip 192.168.1.110 os rhel-5.8 mysql 5.5.28 Slave: ip 192.168.1.113 os rhel-5.8 mysql 5.5.28
① Configure master my. CNF
[Root @ localhost ~] # Cat/etc/My. CNF [mysqld] Log-bin = mysql-bin # Open MySQL binary log BINLOG-do-DB = test # Set the database server-id = 1 # Set mysql_id, the master and slave nodes cannot be the same as BINLOG-ignore-DB = MySQL # Set the database sync_binlog not recorded in binary log = 1 # refresh to disk when BINLOG is updated
② Log on to the master database
use mysql;grant replication slave,file on *.* to 'Think'@'192.168.1.113' identified by 'mysql';flush privileges;
View the status of the master database and record file and Position
mysql> show master status\G;*************************** 1. row *************************** File: mysql-bin.000002 Position: 107 Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)
③ Configuration from my. CNF
[root@localhost ~]# cat /etc/my.cnf[mysqld]log-bin=mysql-binserver-id = 2replicate-do-db=testreplicate-ignore-db=mysqllog-slave-updatessync_binlog=1slave-net-timeout=10
④ Slave Database Change master
mysql> stop slave;Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> change master to -> master_host='192.168.1.110',master_user='Think',master_password='mysql', -> master_log_file='mysql-bin.000002',master_log_pos=107;Query OK, 0 rows affected (0.10 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)mysql> show slave status\G;*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.110 Master_User: Think Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 107 Relay_Log_File: localhost-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: test Replicate_Ignore_DB: mysql 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: 107 Relay_Log_Space: 413 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: 0Master_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: 11 row in set (0.00 sec)
⑤ Verify Synchronization
Master database:
mysql> use test;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables;+----------------+| Tables_in_test |+----------------+| bin || servers || water |+----------------+3 rows in set (0.00 sec)mysql> insert into bin values(1);Query OK, 1 row affected (0.12 sec)
Slave database:
mysql> use test;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables;+----------------+| Tables_in_test |+----------------+| bin || sales || t |+----------------+3 rows in set (0.00 sec)mysql> select * from bin;+------+| id |+------+| 1 |+------+1 row in set (0.00 sec)