从库是192.168.1.70 ,主库是192.168.1.64,主从切换一次

即:主库是192.168.1.70,从库是192.168.1.64

1、从库上执行,修改为主

修改从库为非只读库
修改配置 /etc/my.cnf
read_only = 1
重启mysql
service mysqld_3306 restart

mysql> stop slave io_thread;
Query OK, 0 rows affected (0.07 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.1.64
Master_User: zabbix64
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000147
Read_Master_Log_Pos: 49072513
Relay_Log_File: relay-bin-3306.000179
Relay_Log_Pos: 17594196
Relay_Master_Log_File: mysql-bin.000147
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: 49072513
Relay_Log_Space: 17594368
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: 101
Master_UUID: 9a5386d8-cd13-11e8-96cb-c68297e2a5d7
Master_Info_File: /home/mysql_data/3306/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)

ERROR:
No query specified

mysql> stop slave;
Query OK, 0 rows affected (0.05 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.1.64
Master_User: zabbix64
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000147
Read_Master_Log_Pos: 49072513
Relay_Log_File: relay-bin-3306.000179
Relay_Log_Pos: 17594196
Relay_Master_Log_File: mysql-bin.000147
Slave_IO_Running: No
Slave_SQL_Running: No
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: 49072513
Relay_Log_Space: 17594368
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: 101
Master_UUID: 9a5386d8-cd13-11e8-96cb-c68297e2a5d7
Master_Info_File: /home/mysql_data/3306/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
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)

ERROR:
No query specified

mysql> reset master;
Query OK, 0 rows affected (0.28 sec)

mysql> grant replication slave on *.* to 'repl'@'192.168.1.64' identified by '123456';
Query OK, 0 rows affected (0.05 sec)

2、主上执行(修改为从)

mysql> change master to master_host='192.168.1.70',master_user='repl',master_password='123456';
Query OK, 0 rows affected, 2 warnings (0.31 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)

参考来源 :https://www.cnblogs.com/gomysql/p/3663146.html

msyql 主从切换的更多相关文章

  1. Redis集群(九):Redis Sharding集群Redis节点主从切换后客户端自动重新连接

    上文介绍了Redis Sharding集群的使用,点击阅读 本文介绍当某个Redis节点的Master节点发生问题,发生主从切换时,Jedis怎样自动重连新的Master节点 ​一.步骤如下: 1.配 ...

  2. redis主从配置及主从切换

    环境描述: 主redis:192.168.10.1 6379从redis:192.168.10.2 6380 一.主从配置 1.将主从redis配置文件redis.conf中的aemonize no ...

  3. mysql主从切换

    mysql 主从切换 主停,从做主步骤如下: 1 确认从服务器已经完成所有同步操作:stop slave io_thread show processlist 直到看到状态都为:xxx has rea ...

  4. Sentinel-Redis高可用方案(二):主从切换

    Redis 2.8版开始正式提供名为Sentinel的主从切换方案,Sentinel用于管理多个Redis服务器实例,主要负责三个方面的任务:     1. 监控(Monitoring): Senti ...

  5. redis的主从复制,读写分离,主从切换

    当数据量变得庞大的时候,读写分离还是很有必要的.同时避免一个redis服务宕机,导致应用宕机的情况,我们启用sentinel(哨兵)服务,实现主从切换的功能. redis提供了一个master,多个s ...

  6. redis主从配置及主从切换 转

    redis主从配置及主从切换 转自 http://blog.sina.com.cn/s/blog_67196ddc0101h8v0.html (2014-04-28 17:48:47) 转载▼   分 ...

  7. mysql主从备份、主从切换的例子

    指定binlog(因为时通过binlog实现数据同步的) 配置完后重启数据库服务,用show master status可以看到Master信息. StepB: 在SerB的my.cnf中指定 [ht ...

  8. redis - 主从复制与主从切换

    redis2.8之前本身是不支持分布式管理的,一般建议使用redis3.0及以后版本 redis主从切换的方法 keepalive  或者 使用sentinel线程管理 说明如何使用sentinel实 ...

  9. master_pos_wait函数与MySQL主从切换

    背景 主从切换是高可用MySQL架构的必要步骤(即使用不发生,也要有备无患).一般设置为双M(M1.M2),假设当前状态为写M1,而M2只读,切换的大致流程如下: 1.  停止应用写M1,将M1设置为 ...

随机推荐

  1. fastJson与jackson性能对比

    转载:https://blog.csdn.net/u013433821/article/details/82905222最近项目用到fastJson和jackson,为了决定到底弃用哪个,随手写了个测 ...

  2. OI 常用模板 手写

    线性筛素数 (例题 洛谷P3383) bool p[50000010]; int cnt = 0; int prime[10000010]; inline void init() { int N = ...

  3. Friends (ZOJ - 3710)

    Problem Alice lives in the country where people like to make friends. The friendship is bidirectiona ...

  4. 2019.7.9 校内测试 T3 15数码问题

    这一次是交流测试?边交流边测试(滑稽 15数码问题 大家应该都玩过这个15数码的游戏吧,就在桌面小具库那里面哦. 一看到这个题就知道要GG,本着能骗点分的原则输出了 t 个无解,本来以为要爆零,没想到 ...

  5. 64位linux下玩32位汇编编程

    利用下假期,打算把linux下的汇编语言给熟悉下,结果是以32位为版本的,只能在办公室的机器上跑了个opensuse的32位版本,家里的suse挂了,无法输入中文.打算再安装下32位系统,今天找到了个 ...

  6. Linux设备驱动程序 之 后备高速缓存

    设备驱动程序常常会反复的分配很多相同大小的内存块:内核实现了后备高速缓存来对此进行支持,以反复的使用这些相同的内存块: 创建 Linux内核的高速缓存管理有时被称为“slab分配器”:因此,相关函数和 ...

  7. springboot项目报Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is`...解

    参考文章:https://blog.csdn.net/qq_42815754/article/details/83652253 <!-- MySql驱动 --> <dependenc ...

  8. 以太坊联盟链 parity 节点搭建

    https://www.cnblogs.com/sumingk/articles/9097996.html 上一篇文章介绍了以太坊私有链 geth节点的搭建,本篇介绍下企业级应用 联盟链搭建,运用pa ...

  9. [MyBatis]浅谈如何实现事务处理

    要实现事务处理,就得从SqlSession中取出connection来,然后对connection采用setAutoCommit,commit,rollback等操作,最后的时候,不能像JDBC一样关 ...

  10. 循环引擎 greenlet 没有显式调度的微线程,换言之 协程

    小结: 1. micro-thread with no implicit scheduling; coroutines, in other words. 没有显式调度的微线程,换言之 协程 2. 一个 ...