mysql管理必备工具_Mysql管理必备工具Maatkit详解之十五(mk-slave-restart)

本文介绍了MySQL从库(slave)在遇到错误时如何使用mk-slave-restart工具进行监控和重启,以及如何解析输出信息。mk-slave-restart能够自动检测错误并尝试重启,同时提供详细的错误信息,便于故障排查。参数如run-time用于指定监控时间,skip-count用于设置跳过错误的语句数量。该工具有助于提升MySQL复制的稳定性。
摘要由CSDN通过智能技术生成

其实可以理解成在slave执行了如下命令:

stop slave;

set global sql_slave_skip_counter=1;

start slave;

下面举例说明:

先模拟一个slave报错,在主库建表,然后在从库删除,再去主库删除。报错如下:

Last_SQL_Errno: 1051

Last_SQL_Error: Error 'Unknown table 'test_sg'' on query. Default database: 'test'. Query: 'drop table test_sg'

在利用mk-slave-restart去重启这个slave;

[root@mysql2 ~]# mk-slave-restart -u xxx -p xxx -h xxx --run-time 3 --skip-count 1

2010-03-09T14:01:57 h=xxx,p=...,u=xxx slave-relay-bin.000215 74173942 1051

解释下参数:

run-time:指监控slave的时间,单位是秒;

skip-count:指跳过log的数量;

解释下输出:

1、time

2、slave IP

3、user

4、passwd

5、MASTER_LOG_FILE

6、MASTER_LOG_POS

7、Last_SQL_Errno

很显然mk-slave-restart是一个很不错的slave监控工具,当salve出错后能及时报警,并直接重启slave。同时输出了报错的相关信息,方便后面查询在哪出错,是什么错。下面给出它的帮助:

[root@mysql2 ~]# mk-slave-restart --help

mk-slave-restart watches one or more MySQL replication slaves for errors, and

tries to restart replication if it stops. For more details, please use the

--help option, or try 'perldoc /usr/bin/mk-slave-restart' for complete

documentation.

Usage: /usr/bin/mk-slave-restart Options:

--always Start slaves even when there is no error

--ask-pass Prompt for a password when connecting to MySQL

--charset -A Default character set

--config Read this comma-separated list of config files; if

specified, this must be the first option on the command

line

--daemonize Fork to background and detach (POSIX only)

--database -D Database to use

--defaults-file -F Only read mysql options from the given file

--error-length Max length of error message to print

--error-numbers Only restart this comma-separated list of errors

--error-text Only restart errors that match this pattern

--help Show help and exit

--host -h Connect to host

--log Print all output to this file when daemonized

--max-sleep Maximum sleep seconds (default 64)

--min-sleep The minimum time mk-slave-restart will sleep before

polling the slave again (default 0.015625)

--monitor Whether to monitor the slave (default)

--password -p Password to use when connecting

--pid Create the given PID file when daemonized

--port -P Port number to use for connection

--quiet -q Suppresses normal output (disables --verbose)

--recurse Watch slaves of the specified server, up to the specified

number of servers deep in the hierarchy

--run-time Time to run before exiting. Optional suffix s=seconds,

m=minutes, h=hours, d=days; if no suffix, s is used.

--sentinel Exit if this file exists (default

/tmp/mk-slave-restart-sentinel)

--set-vars Set these MySQL variables (default wait_timeout=10000)

--skip-count Number of statements to skip when restarting the slave

(default 1)

--sleep Initial sleep seconds between checking the slave (default

1)

--socket -S Socket file to use for connection

--stop Stop running instances by creating the sentinel file

--until-master Run until this master log file and position

--until-relay Run until this relay log file and position

--user -u User for login if not current user

--verbose -v Be verbose; can specify multiple times (default 1)

--version Show version and exit

Options and values after processing arguments:

--always FALSE

--ask-pass FALSE

--charset (No value)

--config /etc/maatkit/maatkit.conf,/etc/maatkit/mk-slave-restart.conf,/root/.maatkit.conf,/root/.mk-slave-

restart.conf

--daemonize FALSE

--database (No value)

--defaults-file (No value)

--error-length (No value)

--error-numbers (No value)

--error-text (No value)

--help TRUE

--host (No value)

--log (No value)

--max-sleep 64

--min-sleep 0.015625

--monitor TRUE

--password (No value)

--pid (No value)

--port (No value)

--quiet FALSE

--recurse (No value)

--run-time (No value)

--sentinel /tmp/mk-slave-restart-sentinel

--set-vars wait_timeout=10000

--skip-count 1

--sleep 1

--socket (No value)

--stop FALSE

--until-master (No value)

--until-relay (No value)

--user (No value)

--verbose 1

--version FALSE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值