MySQL主库宕机从库提权

1登录从库数据库,检查同步进程
mysql> show processlist;
Waiting for master to send event IO线程
Slave has read all relay log; waiting for the slave I/O thread to update SQL线程
mysql> show processlist;
±—±------------±----------±-----±--------±-----±----------------------------------------------------------------------------±-----------------+
| Id | User | Host | db | Command | Time | State | Info |
±—±------------±----------±-----±--------±-----±----------------------------------------------------------------------------±-----------------+
| 3 | root | localhost | h2 | Query | 0 | init | show processlist |
| 8 | system user | | NULL | Connect | 773 | Waiting for master to send event | NULL |
| 9 | system user | | NULL | Connect | 697 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |

2 检查所有从库的同步进度,选取与主库最接近的,
[root@web01 ~]# cat /application/mysql/data/master.info
mysql-bin.000006
107 位置点
在所有从库总选取最大的
第二种方法 就对比所有slave 的Exec_Master_Log_Pos:
mysql> show slave status\G
Master_Log_File:
Read_Master_Log_Pos:
Exec_Master_Log_Pos:

3确保所有relay log全部更新完毕
在每个从库上执行
mysql> stop slave io_thread;
mysql> show processlist;
直到看到Slave has read all relay log 表示从库更新都执行完毕

4登录从库执行 提升为master
stop slave;
retset master;

5进入数据库目录,删除master.info relay-log.info 否则下次重启则按照从库启动

6检查用户授权表
mysql> select * from information_schema.user_privileges; 查看全部用户授权信息
也可以查出所有用户,在查寻授权
mysql> select user,host from mysql.user;
mysql> show grants for gao@‘localhost’;

7编辑配置文件
开启 log-bin
如果存在 log-slave-updates read-only等一定要注释掉
重启服务,到此为止提升主库完毕。

8其他从库操作
登录从库
检查同步用户 rep是否存在
stop slave;
change master to master_host = ‘提权的数据库ip’ 如果数据不同步,就指定位置点。
start slave;
开发修改程序连接新的主库

上面讲的是宕机下切库,如果我们是有计划的切换,主库没有宕机
1 主库锁表
2 登录所有的从库查看同步状态是否完成
3 change master to master_host = ‘提权的数据库ip’

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/88133862