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

Writetype and switchtype in Mycat failover

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Mycat failover writetype and switchtype, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

1. The configuration file is as follows:

There are three types of load balancer:

1. WriteType= "0". All write operations are sent to the first writeHost of the configuration, and the first one hangs the second writeHost that is still alive. After restarting, the switch is recorded in the configuration file: dnindex.properties.

2. WriteType= "1", all write operations are randomly sent to the configured writeHost.

3. WriteType= "2", not realized.

The switchtype attribute is as follows (controls automatic switching)

2 analog database downmachine

2.1 main library downmachine

[root@localhost ~] # / etc/init.d/mysql stop

Shutting down MySQL.... [OK]

2.2 mycat insert data

Mysql > insert into zs values (2), (3)

Query OK, 2 rows affected (0.00 sec)

Records: 2 Duplicates: 0 Warnings: 0

2.3 View Reserve Library

Mysql > select * from zs

+-+

| | id |

+-+

| | 1 |

| | 2 |

| | 3 |

+-+

3 rows in set (0.00 sec)

When the data is sent to the standby database, it can be seen that the switch has been successful.

2.4 recovery of the main library

[root@localhost ~] # / etc/init.d/mysql start

Starting MySQL. [OK]

2.5 insert the data again and view the slave and master

Mycat > insert into zs values (4), (5)

From above: mysql > select * from zs

+-+

| | id |

+-+

| | 1 |

| | 2 |

| | 3 |

| | 4 |

| | 5 |

+-+

Main: mysql > select * from zs

+-+

| | id |

+-+

| | 1 |

+-+

1 row in set (0.00 sec)

Through the above steps, we can find that when the master library down is dropped, the slave library will prevail. Even if the master library is restored, the slave library will prevail, so building a double master is the best solution.

You can take a look at the switching record file.

[root@localhost conf] # more dnindex.properties

# update

# Fri Apr 21 13:40:09 CST 2017

Localhost3=0

Localhost2=0

Localhost1=1 # use the second writehost

Restore the new main library and switch back to the original main library.

[root@localhost conf] # more dnindex.properties

# update

# Fri Apr 21 13:56:09 CST 2017

Localhost3=0

Localhost2=0

Localhost1=0 # use the first writehost

# these 0 and 1 denote the number of writehost used when writing

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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