1MK-SLAVE-RESTART(1) User Contributed Perl Documentation MK-SLAVE-RESTART(1)
2
3
4
6 mk-slave-restart - Watch and restart MySQL replication after errors.
7
9 mk-slave-restart --verbose
10
12 The following section is included to inform users about the potential
13 risks, whether known or unknown, of using this tool. The two main
14 categories of risks are those created by the nature of the tool (e.g.
15 read-only tools vs. read-write tools) and those created by bugs.
16
17 mk-slave-restart is a brute-force way to try to keep a slave server
18 running when it is having problems with replication. Don't be too
19 hasty to use it unless you need to. If you use this tool carelessly,
20 you might miss the chance to really solve the slave server's problems.
21
22 At the time of this release there is a bug that causes an invalid
23 "CHANGE MASTER TO" statement to be executed.
24
25 The authoritative source for updated information is always the online
26 issue tracking system. Issues that affect this tool will be marked as
27 such. You can see a list of such issues at the following URL:
28 http://www.maatkit.org/bugs/mk-slave-restart
29 <http://www.maatkit.org/bugs/mk-slave-restart>.
30
31 See also "BUGS" for more information on filing bugs and getting help.
32
34 mk-slave-restart watches one or more MySQL replication slaves and tries
35 to skip statements that cause errors. It polls slaves intelligently
36 with an exponentially varying sleep time. You can specify errors to
37 skip and run the slaves until a certain binlog position.
38
39 Note: it has come to my attention that Yahoo! had or has an internal
40 tool called fix_repl, described to me by a past Yahoo! employee and
41 mentioned in the first edition of High Performance MySQL. Apparently
42 this tool does the same thing. Make no mistake, though: this is not a
43 way to "fix replication." In fact I would not even encourage its use
44 on a regular basis; I use it only when I have an error I know I just
45 need to skip past.
46
48 If you specify "--verbose", mk-slave-restart prints a line every time
49 it sees the slave has an error. See "--verbose" for details.
50
52 mk-slave-restart sleeps intelligently between polling the slave. The
53 current sleep time varies.
54
55 · The initial sleep time is given by "--sleep".
56
57 · If it checks and finds an error, it halves the previous sleep time.
58
59 · If it finds no error, it doubles the previous sleep time.
60
61 · The sleep time is bounded below by "--min-sleep" and above by
62 "--max-sleep".
63
64 · Immediately after finding an error, mk-slave-restart assumes
65 another error is very likely to happen next, so it sleeps the
66 current sleep time or the initial sleep time, whichever is less.
67
69 Successful exit status is 0. Any other value represents the exit
70 status of the Perl process itself, or of the last forked process that
71 exited if there were multiple servers to monitor.
72
74 mk-slave-restart should work on many versions of MySQL. Lettercase of
75 many output columns from SHOW SLAVE STATUS has changed over time, so it
76 treats them all as lowercase.
77
79 --always
80 Start slaves even when there is no error. With this option
81 enabled, mk-slave-restart will not let you stop the slave manually
82 if you want to!
83
84 --ask-pass
85 Prompt for a password when connecting to MySQL.
86
87 --charset
88 short form: -A; type: string
89
90 Default character set. If the value is utf8, sets Perl's binmode
91 on STDOUT to utf8, passes the mysql_enable_utf8 option to
92 DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any
93 other value sets binmode on STDOUT without the utf8 layer, and runs
94 SET NAMES after connecting to MySQL.
95
96 --[no]check-relay-log
97 default: yes
98
99 Check the last relay log file and position before checking for
100 slave errors.
101
102 By default mk-slave-restart will not doing anything (it will just
103 sleep) if neither the relay log file nor the relay log position
104 have changed since the last check. This prevents infinite loops
105 (i.e. restarting the same error in the same relay log file at the
106 same relay log position).
107
108 For certain slave errors, however, this check needs to be disabled
109 by specifying "--no-check-relay-log". Do not do this unless you
110 know what you are doing!
111
112 --config
113 type: Array
114
115 Read this comma-separated list of config files; if specified, this
116 must be the first option on the command line.
117
118 --daemonize
119 Fork to the background and detach from the shell. POSIX operating
120 systems only.
121
122 --database
123 short form: -D; type: string
124
125 Database to use.
126
127 --defaults-file
128 short form: -F; type: string
129
130 Only read mysql options from the given file. You must give an
131 absolute pathname.
132
133 --error-length
134 type: int
135
136 Max length of error message to print. When "--verbose" is set high
137 enough to print the error, this option will truncate the error text
138 to the specified length. This can be useful to prevent wrapping on
139 the terminal.
140
141 --error-numbers
142 type: hash
143
144 Only restart this comma-separated list of errors. Makes mk-slave-
145 restart only try to restart if the error number is in this comma-
146 separated list of errors. If it sees an error not in the list, it
147 will exit.
148
149 The error number is in the "last_errno" column of "SHOW SLAVE
150 STATUS".
151
152 --error-text
153 type: string
154
155 Only restart errors that match this pattern. A Perl regular
156 expression against which the error text, if any, is matched. If
157 the error text exists and matches, mk-slave-restart will try to
158 restart the slave. If it exists but doesn't match, mk-slave-
159 restart will exit.
160
161 The error text is in the "last_error" column of "SHOW SLAVE
162 STATUS".
163
164 --help
165 Show help and exit.
166
167 --host
168 short form: -h; type: string
169
170 Connect to host.
171
172 --log
173 type: string
174
175 Print all output to this file when daemonized.
176
177 --max-sleep
178 type: float; default: 64
179
180 Maximum sleep seconds.
181
182 The maximum time mk-slave-restart will sleep before polling the
183 slave again. This is also the time that mk-slave-restart will wait
184 for all other running instances to quit if both "--stop" and
185 "--monitor" are specified.
186
187 See "SLEEP".
188
189 --min-sleep
190 type: float; default: 0.015625
191
192 The minimum time mk-slave-restart will sleep before polling the
193 slave again. See "SLEEP".
194
195 --monitor
196 Whether to monitor the slave (default). Unless you specify
197 --monitor explicitly, "--stop" will disable it.
198
199 --password
200 short form: -p; type: string
201
202 Password to use when connecting.
203
204 --pid
205 type: string
206
207 Create the given PID file when daemonized. The file contains the
208 process ID of the daemonized instance. The PID file is removed
209 when the daemonized instance exits. The program checks for the
210 existence of the PID file when starting; if it exists and the
211 process with the matching PID exists, the program exits.
212
213 --port
214 short form: -P; type: int
215
216 Port number to use for connection.
217
218 --quiet
219 short form: -q
220
221 Suppresses normal output (disables "--verbose").
222
223 --recurse
224 type: int; default: 0
225
226 Watch slaves of the specified server, up to the specified number of
227 servers deep in the hierarchy. The default depth of 0 means "just
228 watch the slave specified."
229
230 mk-slave-restart examines "SHOW PROCESSLIST" and tries to determine
231 which connections are from slaves, then connect to them. See
232 "--recursion-method".
233
234 Recursion works by finding all slaves when the program starts, then
235 watching them. If there is more than one slave, "mk-slave-restart"
236 uses "fork()" to monitor them.
237
238 This also works if you have configured your slaves to show up in
239 "SHOW SLAVE HOSTS". The minimal configuration for this is the
240 "report_host" parameter, but there are other "report" parameters as
241 well for the port, username, and password.
242
243 --recursion-method
244 type: string
245
246 Preferred recursion method used to find slaves.
247
248 Possible methods are:
249
250 METHOD USES
251 =========== ================
252 processlist SHOW PROCESSLIST
253 hosts SHOW SLAVE HOSTS
254
255 The processlist method is preferred because SHOW SLAVE HOSTS is not
256 reliable. However, the hosts method is required if the server uses
257 a non-standard port (not 3306). Usually mk-slave-restart does the
258 right thing and finds the slaves, but you may give a preferred
259 method and it will be used first. If it doesn't find any slaves,
260 the other methods will be tried.
261
262 --run-time
263 type: time
264
265 Time to run before exiting. Causes mk-slave-restart to stop after
266 the specified time has elapsed. Optional suffix: s=seconds,
267 m=minutes, h=hours, d=days; if no suffix, s is used.
268
269 --sentinel
270 type: string; default: /tmp/mk-slave-restart-sentinel
271
272 Exit if this file exists.
273
274 --set-vars
275 type: string; default: wait_timeout=10000
276
277 Set these MySQL variables. Immediately after connecting to MySQL,
278 this string will be appended to SET and executed.
279
280 --skip-count
281 type: int; default: 1
282
283 Number of statements to skip when restarting the slave.
284
285 --sleep
286 type: int; default: 1
287
288 Initial sleep seconds between checking the slave.
289
290 See "SLEEP".
291
292 --socket
293 short form: -S; type: string
294
295 Socket file to use for connection.
296
297 --stop
298 Stop running instances by creating the sentinel file.
299
300 Causes "mk-slave-restart" to create the sentinel file specified by
301 "--sentinel". This should have the effect of stopping all running
302 instances which are watching the same sentinel file. If
303 "--monitor" isn't specified, "mk-slave-restart" will exit after
304 creating the file. If it is specified, "mk-slave-restart" will
305 wait the interval given by "--max-sleep", then remove the file and
306 continue working.
307
308 You might find this handy to stop cron jobs gracefully if
309 necessary, or to replace one running instance with another. For
310 example, if you want to stop and restart "mk-slave-restart" every
311 hour (just to make sure that it is restarted every hour, in case of
312 a server crash or some other problem), you could use a "crontab"
313 line like this:
314
315 0 * * * * mk-slave-restart --monitor --stop --sentinel /tmp/mk-slave-restartup
316
317 The non-default "--sentinel" will make sure the hourly "cron" job
318 stops only instances previously started with the same options (that
319 is, from the same "cron" job).
320
321 See also "--sentinel".
322
323 --until-master
324 type: string
325
326 Run until this master log file and position. Start the slave, and
327 retry if it fails, until it reaches the given replication
328 coordinates. The coordinates are the logfile and position on the
329 master, given by relay_master_log_file, exec_master_log_pos. The
330 argument must be in the format "file,pos". Separate the filename
331 and position with a single comma and no space.
332
333 This will also cause an UNTIL clause to be given to START SLAVE.
334
335 After reaching this point, the slave should be stopped and mk-
336 slave-restart will exit.
337
338 --until-relay
339 type: string
340
341 Run until this relay log file and position. Like "--until-master",
342 but in the slave's relay logs instead. The coordinates are given
343 by relay_log_file, relay_log_pos.
344
345 --user
346 short form: -u; type: string
347
348 User for login if not current user.
349
350 --verbose
351 short form: -v; cumulative: yes; default: 1
352
353 Be verbose; can specify multiple times. Verbosity 1 outputs
354 connection information, a timestamp, relay_log_file, relay_log_pos,
355 and last_errno. Verbosity 2 adds last_error. See also
356 "--error-length". Verbosity 3 prints the current sleep time each
357 time mk-slave-restart sleeps.
358
359 --version
360
361 Show version and exit.
362
364 These DSN options are used to create a DSN. Each option is given like
365 "option=value". The options are case-sensitive, so P and p are not the
366 same option. There cannot be whitespace before or after the "=" and if
367 the value contains whitespace it must be quoted. DSN options are
368 comma-separated. See the maatkit manpage for full details.
369
370 · A
371
372 dsn: charset; copy: yes
373
374 Default character set.
375
376 · D
377
378 dsn: database; copy: yes
379
380 Default database.
381
382 · F
383
384 dsn: mysql_read_default_file; copy: yes
385
386 Only read default options from the given file
387
388 · h
389
390 dsn: host; copy: yes
391
392 Connect to host.
393
394 · p
395
396 dsn: password; copy: yes
397
398 Password to use when connecting.
399
400 · P
401
402 dsn: port; copy: yes
403
404 Port number to use for connection.
405
406 · S
407
408 dsn: mysql_socket; copy: yes
409
410 Socket file to use for connection.
411
412 · u
413
414 dsn: user; copy: yes
415
416 User for login if not current user.
417
419 You can download Maatkit from Google Code at
420 <http://code.google.com/p/maatkit/>, or you can get any of the tools
421 easily with a command like the following:
422
423 wget http://www.maatkit.org/get/toolname
424 or
425 wget http://www.maatkit.org/trunk/toolname
426
427 Where "toolname" can be replaced with the name (or fragment of a name)
428 of any of the Maatkit tools. Once downloaded, they're ready to run; no
429 installation is needed. The first URL gets the latest released version
430 of the tool, and the second gets the latest trunk code from Subversion.
431
433 The environment variable "MKDEBUG" enables verbose debugging output in
434 all of the Maatkit tools:
435
436 MKDEBUG=1 mk-....
437
438 When "--daemonize" is given and this variable is set, output is
439 directed to a debug file in "/tmp".
440
442 You need Perl, DBI, DBD::mysql, and some core packages that ought to be
443 installed in any reasonably new version of Perl.
444
446 For list of known bugs see http://www.maatkit.org/bugs/mk-slave-restart
447 <http://www.maatkit.org/bugs/mk-slave-restart>.
448
449 Please use Google Code Issues and Groups to report bugs or request
450 support: <http://code.google.com/p/maatkit/>. You can also join
451 #maatkit on Freenode to discuss Maatkit.
452
453 Please include the complete command-line used to reproduce the problem
454 you are seeing, the version of all MySQL servers involved, the complete
455 output of the tool when run with "--version", and if possible,
456 debugging output produced by running with the "MKDEBUG=1" environment
457 variable.
458
460 This program is copyright 2007-2010 Baron Schwartz. Feedback and
461 improvements are welcome.
462
463 THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
464 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
465 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
466
467 This program is free software; you can redistribute it and/or modify it
468 under the terms of the GNU General Public License as published by the
469 Free Software Foundation, version 2; OR the Perl Artistic License. On
470 UNIX and similar systems, you can issue `man perlgpl' or `man
471 perlartistic' to read these licenses.
472
473 You should have received a copy of the GNU General Public License along
474 with this program; if not, write to the Free Software Foundation, Inc.,
475 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
476
478 See also mk-table-checksum, mk-table-sync, mk-slave-delay.
479
481 Baron Schwartz
482
484 This tool is part of Maatkit, a toolkit for power users of MySQL.
485 Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the
486 primary code contributors. Both are employed by Percona. Financial
487 support for Maatkit development is primarily provided by Percona and
488 its clients.
489
491 This manual page documents Ver 1.0.22 Distrib 6839 $Revision: 6836 $.
492
493
494
495perl v5.12.1 2010-08-01 MK-SLAVE-RESTART(1)