切换主从:

  1. 从库都已经执行完了relay log 中的全部更新:

mysql> stop slave io_thread;

Query OK, 0 rows affected (0.06 sec)


mysql> show processlist\G   

*************************** 1. row ***************************

     Id: 6

   User: system user

   Host: 

     db: NULL

Command: Connect

   Time: 2144

  State: Slave has read all relay log; waiting for the slave I/O thread to update it

   Info: NULL


2.停止slave

mysql> stop slave io_thread;

Query OK, 0 rows affected (0.06 sec)


[root@192 /]# grep log-bin  /data/3307/my.cnf 

log-bin=/data/3307/mysql3307-bin

[root@192 /]# 


[root@192 ~]# /usr/bin/mysqladmin -p3307 --socket=/data/3307/mysql.sock shutdown 

[root@192 ~]# /opt/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &

[root@192 ~]# /usr/bin/mysql -p3307 --socket=/data/3307/mysql.sock 



3.reset master

mysql> stop slave ;

Query OK, 0 rows affected (0.13 sec)


mysql> reset master;

Query OK, 0 rows affected (0.41 sec)


mysql> 



4.删除master.info  relay-log.info


5.从库要打开log-bin ,关闭log-slave-updates,关闭read-only。