Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Matters needing attention of mysql master-slave switch

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "matters needing attention in mysql master-slave switching". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Use the vip address to switch between master and slave:

1. Add a lock to the original main library: flush tables with read lock

2. Open read_only; on top of the original main library [now the main library binlog will no longer change show master status]

3. # # check the location to which the new main database is currently applied [make sure that the sql_thread location and io_thread location are the same] to ensure that the data is not lost

# # check the binlog file and location on the new main library: show master status; (prepare for the following main library)

Master_Log_File: mysql-bin.000572

Read_Master_Log_Pos: 423689861

Relay_Master_Log_File: mysql-bin.000572

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Exec_Master_Log_Pos: 423689861

4. Remove vip from the original main library: / sbin/ifconfig eth2:1 down; pay attention to the port of the network card

5. Add vip to the new main library: / sbin/ifconfig eth2:1 192.168.7.71

6. The connection above the original main library of kill: for example:

Mysql-uroot-proot-h227.0.0.1-P3307-e "show processlist;" | egrep 'Sleep' | awk' {print "kill" $1 ";"}'| mysql-uroot-proot-h227.0.0.1-P3307

7. Above the new main library: reset slave all

Check the binlog location again (prepare for the slave library of the new master library)

8. Close read_only on the new main library

9. Make sure it is not written on the original main library. Unlock: unlock

10. Point the original master library to the new master library: change master to

Note:

1the ip used in the master-slave connection of the IDC machine is vip.

2. Delete the master.info and relay-log.info files on the new master database server, otherwise the slave library will be started the next time you restart.

This is the end of the content of "matters needing attention for mysql master-slave switching". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report