mysqlfailover: A MySQL tool that inspects the master for failure and executes failover
mysqlfailover is a utility that allows users to replicate health monitoring. It can also automatically switch to a slave database when your master has failed. It is architected to work interactively or run while continuously updating the health information at regular intervals. mysqlfailover monitors the master database and should it fail, it then fails over to the next available slave. It can choose from a list of slaves that it can consider as candidate slaves.
The mysqlfailover utility works when you have the GTID-replication in MySQL 5.6 enabled.
How to use mysqlfailover
You can specify the interval you want using the –interval option. mysqlfailover will check to see if the master server is operational using a ping operation and then checking the connector to see if the server is still working. You can control the ping operation using the –ping option.
If the master is offline, the mysqlfailover utility will then execute the actions you have specified on the –failover-mode option. These actions are:
- auto, which executes automatic failover using a list of candidate slaves, and then evaluates all the other slaves available. If no slaves are found to be suitable, the mysqlfailover utility will exit after registering an error.
- elect, which works the same way as auto. The only difference is that in elect mode, the utility only considers the list of candidate slaves and ignores all the other slaves that are in the system. If none of the candidate slaves are suitable, the mysqlfailover utility signifies an error and then exits.
- fail, which causes the mysqlfailover utility to generate an error before exiting. It will not promote a slave as master when the master fails. You can use this mode when you want the mysqlfailover utility to do regular health monitoring without doing any failover.
Discovering slaves connected to the master
You can also use the mysqlfailover utility to discover all slaves that are connected to the master. You must use the –report-host and –report-port variables on all slaves to get the right hostname and ip port of the slave. If you do not have the correct ip port or hostname, you would not be able to monitor the health of the slaves or they may remain unlisted.
Run an external script before and after a failover. If you have external scripts that you want to run in the event that your master server fails, then you can specify these scripts using the –exec-after and –exec-before options.
Other important options you should know include:
- You can use the –log option to log everything that happens during commands.
- You can get help using the –help option.
- You can view license information using the –license option.
- You can run a daemon, using the –daemon=<command> option. Valid commands are start, stop, nodetach and restart.
- You can use –force to override any registration check on master.
Need help with the mysqlfailover utility? Contact Four Cornerstone using our contact form and work with a team of MySQL and Oracle experts who can help you get off the ground with your IT investments.
Screenshot courtesy of MySQL.