Master-slave switchover for mysql database master-slave database configuration. Mysql master-slave database configuration-master-slave switchover MySQL: master-slave Replication (Replication) construction introduces the MySQL master-slave configuration process. This article introduces the manual master-slave switchover process. Environment Information Master mysql master/slave database configuration master/slave switchover
MySQL: master-slave Replication (Replication) setup introduces the MySQL master-slave configuration process. This article introduces the manual master-slave switchover process.
I. Environment Information
Master Database 192.168.1.60/3306 host name db1
Slave Database 192.168.1.61/3306 host name db2
Note: The Master-Slave node mysql installation and Replication installation are omitted.
Dual-master-slave switchover
-- Master and slave nodes must all create Replication users. If not, refer to create below.
create user 'rep1'@'%' identified by 'rep1abcd1243d'; GRANT REPLICATION SLAVE ON *.* TO 'rep1'@'%';
-- Query slave database status
root@localhost:francs>show slave status\G
-- Query the status of the master database
root@localhost:francs>show slave hosts; +-----------+-------------------+------+-----------+--------------------------------------+ | Server_id | Host | Port | Master_id | Slave_UUID | +-----------+-------------------+------+-----------+--------------------------------------+ | 2 | 192.168.2.38(db2) | 3306 | 1 | ad397a06-7c56-11e4-b2fb-000c29dcb3b5 | +-----------+-------------------+------+-----------+--------------------------------------+ 1 row in set (0.00 sec)
-- Slave Database: stop IO_THREAD
root@localhost:francs>stop slave IO_THREAD; root@localhost:francs>show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.2.37 Master_User: rep1 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin-log.000001 Read_Master_Log_Pos: 362 Relay_Log_File: db2-relay-bin.000002 Relay_Log_Pos: 523 Relay_Master_Log_File: bin-log.000001 Slave_IO_Running: No 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: 362 Relay_Log_Space: 694 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: NULL 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 Master_UUID: 0c130d47-22bb-11e4-aaaa-000c2986ac80 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)
-- Activate slave database (operate on slave database)
root@localhost:francs>stop slave; root@localhost:francs>reset master; root@localhost:francs>reset slave all; root@localhost:francs>show binary logs; +----------------+-----------+ | Log_name | File_size | +----------------+-----------+ | bin-log.000001 | 120 | +----------------+-----------+ 1 row in set (0.00 sec)
Note: The reset slave all command will delete the replication parameter of the slave database, and the show slave status \ G information will return blank.
-- Change the original master database to slave database
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.61', MASTER_PORT=3306, MASTER_USER='rep1', MASTER_PASSWORD='rep1abcd1243d', MASTER_LOG_FILE='bin-log.000001', MASTER_LOG_POS=120; root@localhost:francs>start slave; root@localhost:francs>show slave status\G
Note: After this step, the following error is reported in the db1 log file, indicating that db1 cannot connect to db2.
-- Db1 log error
2015-03-02 14:24:14 26198 [ERROR] Slave I/O: error connecting to master 'rep1@192.168.1.61:3306' - retry-time: 60 retries: 8, Error_code: 1045
-- Solution process
-- Connection test [mysql @ db1 ~] $ Mysql-h 192.168.1.60-P 3306-urep1 note: you can directly connect to mysql without a password. -- Test anonymous users [mysql @ db1 ~] $ Mysql-h 192.168.1.60-P 3306-urep2 note: No password is required. -- Cause analysis root @ localhost: francs> select Host, User, Password from mysql. user where User = ''; + ----------- + ------ + ---------- + | Host | User | Password | + ----------- + ------ + ---------- + | localhost | db1 | + ----------- + ------ + ---------- + remarks: the original db2 node contains two rows with empty User, indicating that anonymous users can connect to the database, delete the two rows, and then flush privileges; -- connect and test [mysql @ db1 ~] $ Mysql-h 192.168.1.60-P 3306-urep1 remarks: The password is required for this connection. Then watch the db1 synchronization log again and no error is reported.
3. data verification
After the master-slave switchover, db2 is the master node and db1 is the slave node. Insert a data entry on the db2 node to test whether the synchronization is normal.
-- Run on db2
root@localhost:francs>insert into test_sr(id) values(30); Query OK, 1 row affected (0.03 sec) root@localhost:francs>select * from test_sr order by id desc limit 1; +------+---------------------+ | id | create_time | +------+---------------------+ | 30 | 2015-03-02 15:19:53 | +------+---------------------+ 1 row in set (0.00 sec)
-- Db1 verification
root@localhost:francs>select * from test_sr order by id desc limit 1; +------+---------------------+ | id | create_time | +------+---------------------+ | 30 | 2015-03-02 15:19:53 | +------+---------------------+ 1 row in set (0.00 sec)
Note: Data Synchronization is normal. the above is the first understanding of MySQL master/slave switchover and will be supplemented later.Slave MySQL: master-slave Replication (Replication) setup introduces the MySQL master-slave configuration process. This article introduces the manual master-slave switchover process. An Environment Information master...