mysqld_multi.sh 22 KB
Newer Older
1
#!/usr/bin/perl
2 3 4 5 6

use Getopt::Long;
use POSIX qw(strftime);

$|=1;
7 8 9
$VER="2.16";

my @defaults_options;   #  Leading --no-defaults, --defaults-file, etc.
10 11 12

$opt_example       = 0;
$opt_help          = 0;
13
$opt_log           = undef();
unknown's avatar
unknown committed
14
$opt_mysqladmin    = "@bindir@/mysqladmin";
unknown's avatar
unknown committed
15
$opt_mysqld        = "@libexecdir@/mysqld";
16 17 18 19 20
$opt_no_log        = 0;
$opt_password      = undef();
$opt_tcp_ip        = 0;
$opt_user          = "root";
$opt_version       = 0;
21
$opt_silent        = 0;
unknown's avatar
unknown committed
22
$opt_verbose       = 0;
23

24 25 26
my $my_print_defaults_exists= 1;
my $logdir= undef();

27 28 29 30 31 32 33 34 35 36 37 38 39 40
my ($mysqld, $mysqladmin, $groupids, $homedir, $my_progname);

$homedir = $ENV{HOME};
$my_progname = $0;
$my_progname =~ s/.*[\/]//;

main();

####
#### main sub routine
####

sub main
{
41
  my $flag_exit= 0;
42 43 44 45 46

  if (!defined(my_which(my_print_defaults)))
  {
    # We can't throw out yet, since --version, --help, or --example may
    # have been given
47
    print "WARNING: my_print_defaults command not found.\n";
unknown's avatar
unknown committed
48 49 50
    print "Please make sure you have this command available and\n";
    print "in your path. The command is available from the latest\n";
    print "MySQL distribution.\n";
51
    $my_print_defaults_exists= 0;
52
  }
53 54 55 56 57 58 59 60 61 62 63

  # Remove leading defaults options from @ARGV
  while (@ARGV > 0)
  {
    last unless $ARGV[0] =~
      /^--(?:no-defaults$|(?:defaults-file|defaults-extra-file)=)/;
    push @defaults_options, (shift @ARGV);
  }

  # Handle deprecated --config-file option: convert to --defaults-extra-file
  foreach my $arg (@ARGV)
64
  {
65
    if ($arg =~ m/^--config-file=(.*)/)
66
    {
67 68 69 70
      # Put it at the beginning of the list, so it has lower precedence
      # than a correct --defaults-extra-file option

      unshift @defaults_options, "--defaults-extra-file=$1";
71
    }
72
  }
73 74

  foreach (@defaults_options)
75
  {
76
    $_ = quote_shell_word($_);
77
  }
78 79 80 81 82 83 84 85 86 87 88 89 90

  # Add [mysqld_multi] options to front of @ARGV, ready for GetOptions()
  unshift @ARGV, defaults_for_group('mysqld_multi');

  # The --config-file option can be ignored; if passed on the command
  # line, it's already handled; if specified in the configuration file,
  # it's redundant and not useful
  @ARGV= grep { not /^--config-file=/ } @ARGV;

  # We've already handled --no-defaults, --defaults-file, etc.
  if (!GetOptions("help", "example", "version", "mysqld=s", "mysqladmin=s",
                  "user=s", "password=s", "log=s", "no-log",
                  "tcp-ip",  "silent", "verbose"))
91
  {
92
    $flag_exit= 1;
93
  }
94
  usage() if ($opt_help);
95

96 97
  if ($opt_verbose && $opt_silent)
  {
98
    print "Both --verbose and --silent have been given. Some of the warnings ";
99 100 101
    print "will be disabled\nand some will be enabled.\n\n";
  }

unknown's avatar
unknown committed
102
  init_log() if (!defined($opt_log));
103 104 105 106 107 108 109 110 111
  $groupids = $ARGV[1];
  if ($opt_version)
  {
    print "$my_progname version $VER by Jani Tolonen\n";
    exit(0);
  }
  example() if ($opt_example);
  if ($flag_exit)
  {
112
    print "Error with an option, see $my_progname --help for more info.\n";
113 114 115 116
    exit(1);
  }
  if (!defined(my_which(my_print_defaults)))
  {
117
    print "ABORT: Can't find command 'my_print_defaults'.\n";
118 119 120 121 122
    print "This command is available from the latest MySQL\n";
    print "distribution. Please make sure you have the command\n";
    print "in your PATH.\n";
    exit(1);
  }
unknown's avatar
unknown committed
123
  usage() if (!defined($ARGV[0]) ||
unknown's avatar
unknown committed
124 125 126
	      (!($ARGV[0] =~ m/^start$/i) &&
	       !($ARGV[0] =~ m/^stop$/i) &&
	       !($ARGV[0] =~ m/^report$/i)));
unknown's avatar
unknown committed
127

128 129 130 131 132 133 134 135 136 137 138
  if (!$opt_no_log)
  {
    w2log("$my_progname log file version $VER; run: ",
	  "$opt_log", 1, 0);
  }
  else
  {
    print "$my_progname log file version $VER; run: ";
    print strftime "%a %b %e %H:%M:%S %Y", localtime;
    print "\n";
  }
unknown's avatar
unknown committed
139
  if ($ARGV[0] =~ m/^start$/i)
140
  {
unknown's avatar
unknown committed
141
    if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
142
    {
unknown's avatar
unknown committed
143
      print "WARNING: Couldn't find the default mysqld binary.\n";
144
      print "Tried: $opt_mysqld\n";
unknown's avatar
unknown committed
145 146
      print "This is OK, if you are using option \"mysqld=...\" in ";
      print "groups [mysqldN] separately for each.\n\n";
147
    }
148 149 150 151
    start_mysqlds();
  }
  else
  {
unknown's avatar
unknown committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    if (!defined(($mysqladmin= my_which($opt_mysqladmin))) && $opt_verbose)
    {
      print "WARNING: Couldn't find the default mysqladmin binary.\n";
      print "Tried: $opt_mysqladmin\n";
      print "This is OK, if you are using option \"mysqladmin=...\" in ";
      print "groups [mysqldN] separately for each.\n\n";
    }
    if ($ARGV[0] =~ m/^report$/i)
    {
      report_mysqlds();
    }
    else
    {
      stop_mysqlds();
    }
167 168 169
  }
}

170 171 172
#
# Quote word for shell
#
173

174
sub quote_shell_word
175 176 177
{
  my ($option)= @_;

178
  $option =~ s!([^\w=./-])!\\$1!g;
179 180 181
  return $option;
}

182 183 184 185 186 187 188 189 190 191 192 193
sub defaults_for_group
{
  my ($group) = @_;

  return () unless $my_print_defaults_exists;

  my $com= join ' ', 'my_print_defaults', @defaults_options, $group;
  my @defaults = `$com`;
  chomp @defaults;
  return @defaults;
}

194 195
####
#### Init log file. Check for appropriate place for log file, in the following
196
#### order:  my_print_defaults mysqld datadir, @datadir@
197 198
####

199 200
sub init_log
{
201
  foreach my $opt (defaults_for_group('mysqld'))
202
  {
203
    if ($opt =~ m/^--datadir=(.*)/ && -d "$1" && -w "$1")
204
    {
205
      $logdir= $1;
206 207 208 209 210 211 212 213 214 215
    }
  }
  if (!defined($logdir))
  {
    $logdir= "@datadir@" if (-d "@datadir@" && -w "@datadir@");
  }
  if (!defined($logdir))
  {
    # Log file was not specified and we could not log to a standard place,
    # so log file be disabled for now.
216 217 218 219
    if (!$opt_silent)
    {
      print "WARNING: Log file disabled. Maybe directory or file isn't writable?\n";
    }
220 221 222 223 224 225 226 227
    $opt_no_log= 1;
  }
  else
  {
    $opt_log= "$logdir/mysqld_multi.log";
  }
}

228 229 230 231 232 233
####
#### Report living and not running MySQL servers
####

sub report_mysqlds
{
unknown's avatar
unknown committed
234
  my (@groups, $com, $i, @options, $pec);
235 236 237 238 239 240 241 242 243

  print "Reporting MySQL servers\n";
  if (!$opt_no_log)
  {
    w2log("\nReporting MySQL servers","$opt_log",0,0);
  }
  @groups = &find_groups($groupids);
  for ($i = 0; defined($groups[$i]); $i++)
  {
unknown's avatar
unknown committed
244
    $com= get_mysqladmin_options($i, @groups);
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    $com.= " ping >> /dev/null 2>&1";
    system($com);
    $pec = $? >> 8;
    if ($pec)
    {
      print "MySQL server from group: $groups[$i] is not running\n";
      if (!$opt_no_log)
      {
	w2log("MySQL server from group: $groups[$i] is not running",
	      "$opt_log", 0, 0);
      }
    }
    else
    {
      print "MySQL server from group: $groups[$i] is running\n";
      if (!$opt_no_log)
      {
	w2log("MySQL server from group: $groups[$i] is running",
	      "$opt_log", 0, 0);
      }
    }
  }
  if (!$i)
  {
    print "No groups to be reported (check your GNRs)\n";
    if (!$opt_no_log)
    {
      w2log("No groups to be reported (check your GNRs)", "$opt_log", 0, 0);
    }
  }
}

####
#### start multiple servers
####

sub start_mysqlds()
{
283
  my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent);
284 285 286 287 288 289 290 291 292 293 294 295

  if (!$opt_no_log)
  {
    w2log("\nStarting MySQL servers\n","$opt_log",0,0);
  }
  else
  {
    print "\nStarting MySQL servers\n";
  }
  @groups = &find_groups($groupids);
  for ($i = 0; defined($groups[$i]); $i++)
  {
296
    @options = defaults_for_group($groups[$i]);
297

298 299
    $mysqld_found= 1; # The default
    $mysqld_found= 0 if (!length($mysqld));
300 301
    $com= "$mysqld";
    for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
302
    {
unknown's avatar
unknown committed
303 304 305 306 307
      if ("--mysqladmin=" eq substr($options[$j], 0, 13))
      {
	# catch this and ignore
      }
      elsif ("--mysqld=" eq substr($options[$j], 0, 9))
308 309 310
      {
	$options[$j]=~ s/\-\-mysqld\=//;
	$com= $options[$j];
311
        $mysqld_found= 1;
312 313 314
      }
      else
      {
315
	$options[$j]= quote_shell_word($options[$j]);
316 317
	$tmp.= " $options[$j]";
      }
318
    }
319 320 321 322 323 324 325 326 327
    if ($opt_verbose && $com =~ m/\/safe_mysqld$/ && !$info_sent)
    {
      print "WARNING: safe_mysqld is being used to start mysqld. In this case you ";
      print "may need to pass\n\"ledir=...\" under groups [mysqldN] to ";
      print "safe_mysqld in order to find the actual mysqld binary.\n";
      print "ledir (library executable directory) should be the path to the ";
      print "wanted mysqld binary.\n\n";
      $info_sent= 1;
    }
328
    $com.= $tmp;
329 330
    $com.= " >> $opt_log 2>&1" if (!$opt_no_log);
    $com.= " &";
331 332
    if (!$mysqld_found)
    {
unknown's avatar
unknown committed
333
      print "\n";
334 335
      print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
      print "but no mysqld binary was found.\n";
unknown's avatar
unknown committed
336
      print "Please add \"mysqld=...\" in group [mysqld_multi], or add it to ";
337 338 339
      print "group [$groups[$i]] separately.\n";
      exit(1);
    }
340 341 342 343
    system($com);
  }
  if (!$i && !$opt_no_log)
  {
unknown's avatar
unknown committed
344
    w2log("No MySQL servers to be started (check your GNRs)",
345 346 347 348 349 350 351 352 353 354
	  "$opt_log", 0, 0);
  }
}

####
#### stop multiple servers
####

sub stop_mysqlds()
{
unknown's avatar
unknown committed
355
  my (@groups, $com, $i, @options);
356 357 358 359 360 361 362 363 364 365 366 367

  if (!$opt_no_log)
  {
    w2log("\nStopping MySQL servers\n","$opt_log",0,0);
  }
  else
  {
    print "\nStopping MySQL servers\n";
  }
  @groups = &find_groups($groupids);
  for ($i = 0; defined($groups[$i]); $i++)
  {
unknown's avatar
unknown committed
368
    $com= get_mysqladmin_options($i, @groups);
369 370 371 372 373 374 375
    $com.= " shutdown";
    $com.= " >> $opt_log 2>&1" if (!$opt_no_log);
    $com.= " &";
    system($com);
  }
  if (!$i && !$opt_no_log)
  {
unknown's avatar
unknown committed
376
    w2log("No MySQL servers to be stopped (check your GNRs)",
377 378 379 380
	  "$opt_log", 0, 0);
  }
}

unknown's avatar
unknown committed
381 382 383 384 385 386 387 388 389
####
#### Sub function for mysqladmin option parsing
####

sub get_mysqladmin_options
{
  my ($i, @groups)= @_;
  my ($mysqladmin_found, $com, $tmp, $j);

390
  @options = defaults_for_group($groups[$i]);
unknown's avatar
unknown committed
391 392 393 394 395

  $mysqladmin_found= 1; # The default
  $mysqladmin_found= 0 if (!length($mysqladmin));
  $com = "$mysqladmin";
  $tmp = " -u $opt_user";
396 397 398 399 400 401
  if (defined($opt_password)) {
    my $pw= $opt_password;
    # Protect single quotes in password
    $pw =~ s/'/'"'"'/g;
    $tmp.= " -p'$pw'";
  }
unknown's avatar
unknown committed
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
  $tmp.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
  for ($j = 0; defined($options[$j]); $j++)
  {
    if ("--mysqladmin=" eq substr($options[$j], 0, 13))
    {
      $options[$j]=~ s/\-\-mysqladmin\=//;
      $com= $options[$j];
      $mysqladmin_found= 1;
    }
    elsif ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
	   ($options[$j] =~ m/^(\-\-port\=)(.*)$/))
    {
      $tmp.= " $options[$j]";
    }
  }
  if (!$mysqladmin_found)
  {
    print "\n";
    print "FATAL ERROR: Tried to use mysqladmin in group [$groups[$i]], ";
    print "but no mysqladmin binary was found.\n";
    print "Please add \"mysqladmin=...\" in group [mysqld_multi], or ";
    print "in group [$groups[$i]].\n";
    exit(1);
  }
  $com.= $tmp;
  return $com;
}

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
# Return a list of option files which can be opened.  Similar, but not
# identical, to behavior of my_search_option_files()
sub list_defaults_files
{
  my %opt;
  foreach (@defaults_options)
  {
    return () if /^--no-defaults$/;
    $opt{$1} = $2 if /^--defaults-(extra-file|file)=(.*)$/;
  }

  return ($opt{file}) if exists $opt{file};

  my %seen;  # Don't list the same file more than once
  return grep { defined $_ and not $seen{$_}++ and -f $_ and -r $_ }
              ('/etc/my.cnf',
               '/etc/mysql/my.cnf',
               '@sysconfdir@/my.cnf',
               ($ENV{MYSQL_HOME} ? "$ENV{MYSQL_HOME}/my.cnf" : undef),
               $opt{'extra-file'},
               ($ENV{HOME} ? "$ENV{HOME}/.my.cnf" : undef));
}

453

454 455
# Takes a specification of GNRs (see --help), and returns a list of matching
# groups which actually are mentioned in a relevant config file
456 457 458 459
sub find_groups
{
  my ($raw_gids) = @_;

460 461 462
  my %gids;
  my @groups;

463 464
  if (defined($raw_gids))
  {
465 466
    # Make a hash of the wanted group ids
    foreach my $raw_gid (split ',', $raw_gids)
467
    {
468 469 470 471
      # Match 123 or 123-456
      my ($start, $end) = ($raw_gid =~ /^\s*(\d+)(?:\s*-\s*(\d+))?\s*$/);
      $end = $start if not defined $end;
      if (not defined $start or $end < $start or $start < 0)
472
      {
473 474
        print "ABORT: Bad GNR: $raw_gid; see $my_progname --help\n";
        exit(1);
475
      }
476 477

      foreach my $i ($start .. $end)
478
      {
479 480
        # Use $i + 0 to normalize numbers (002 + 0 -> 2)
        $gids{$i + 0}= 1;
481 482 483
      }
    }
  }
484 485 486 487

  my @defaults_files = list_defaults_files();
  #warn "@{[sort keys %gids]} -> @defaults_files\n";
  foreach my $file (@defaults_files)
488
  {
489 490 491
    next unless open CONF, "< $file";

    while (<CONF>)
492
    {
493
      if (/^\s*\[\s*(mysqld)(\d+)\s*\]\s*$/)
494
      {
495 496 497 498 499 500
        #warn "Found a group: $1$2\n";
        # Use $2 + 0 to normalize numbers (002 + 0 -> 2)
        if (not defined($raw_gids) or $gids{$2 + 0})
        {
          push @groups, "$1$2";
        }
501 502
      }
    }
503 504

    close CONF;
505 506 507 508 509
  }
  return @groups;
}

####
unknown's avatar
unknown committed
510
#### w2log: Write to a logfile.
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
#### 1.arg: append to the log file (given string, or from a file. if a file,
####        file will be read from $opt_logdir)
#### 2.arg: logfile -name (w2log assumes that the logfile is in $opt_logdir).
#### 3.arg. 0 | 1, if true, print current date to the logfile. 3. arg will
####        be ignored, if 1. arg is a file.
#### 4.arg. 0 | 1, if true, first argument is a file, else a string
####

sub w2log
{
  my ($msg, $file, $date_flag, $is_file)= @_;
  my (@data);

  open (LOGFILE, ">>$opt_log")
    or die "FATAL: w2log: Couldn't open log file: $opt_log\n";

  if ($is_file)
  {
unknown's avatar
unknown committed
529 530
    open (FROMFILE, "<$msg") && (@data=<FROMFILE>) &&
      close(FROMFILE)
531 532 533 534 535 536 537
	or die "FATAL: w2log: Couldn't open file: $msg\n";
    foreach my $line (@data)
    {
      print LOGFILE "$line";
    }
  }
  else
unknown's avatar
unknown committed
538
  {
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
    print LOGFILE "$msg";
    print LOGFILE strftime "%a %b %e %H:%M:%S %Y", localtime if ($date_flag);
    print LOGFILE "\n";
  }
  close (LOGFILE);
  return;
}

####
#### my_which is used, because we can't assume that every system has the
#### which -command. my_which can take only one argument at a time.
#### Return values: requested system command with the first found path,
#### or undefined, if not found.
####

sub my_which
{
  my ($command) = @_;
  my (@paths, $path);

  return $command if (-f $command && -x $command);
  @paths = split(':', $ENV{'PATH'});
  foreach $path (@paths)
  {
    $path .= "/$command";
    return $path if (-f $path && -x $path);
  }
  return undef();
}


####
#### example
####

sub example
{
  print <<EOF;
577 578
# This is an example of a my.cnf file for $my_progname.
# Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf
579
#
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
# SOME IMPORTANT NOTES FOLLOW:
#
# 1.COMMON USER
#
#   Make sure that the MySQL user, who is stopping the mysqld services, has
#   the same password to all MySQL servers being accessed by $my_progname.
#   This user needs to have the 'Shutdown_priv' -privilege, but for security
#   reasons should have no other privileges. It is advised that you create a
#   common 'multi_admin' user for all MySQL servers being controlled by
#   $my_progname. Here is an example how to do it:
#
#   GRANT SHUTDOWN ON *.* TO multi_admin\@localhost IDENTIFIED BY 'password'
#
#   You will need to apply the above to all MySQL servers that are being
#   controlled by $my_progname. 'multi_admin' will shutdown the servers
#   using 'mysqladmin' -binary, when '$my_progname stop' is being called.
#
# 2.PID-FILE
#
#   If you are using mysqld_safe to start mysqld, make sure that every
#   MySQL server has a separate pid-file. In order to use mysqld_safe
#   via $my_progname, you need to use two options:
#
#   mysqld=/path/to/mysqld_safe
#   ledir=/path/to/mysqld-binary/
#
#   ledir (library executable directory), is an option that only mysqld_safe
#   accepts, so you will get an error if you try to pass it to mysqld directly.
#   For this reason you might want to use the above options within [mysqld#]
#   group directly.
#
# 3.DATA DIRECTORY
#
#   It is NOT advised to run many MySQL servers within the same data directory.
#   You can do so, but please make sure to understand and deal with the
#   underlying caveats. In short they are:
#   - Speed penalty
#   - Risk of table/data corruption
#   - Data synchronising problems between the running servers
unknown's avatar
unknown committed
619
#   - Heavily media (disk) bound
620
#   - Relies on the system (external) file locking
unknown's avatar
unknown committed
621 622
#   - Is not applicable with all table types. (Such as InnoDB)
#     Trying so will end up with undesirable results.
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
#
# 4.TCP/IP Port
#
#   Every server requires one and it must be unique.
#
# 5.[mysqld#] Groups
#
#   In the example below the first and the fifth mysqld group was
#   intentionally left out. You may have 'gaps' in the config file. This
#   gives you more flexibility.
#
# 6.MySQL Server User
#
#   You can pass the user=... option inside [mysqld#] groups. This
#   can be very handy in some cases, but then you need to run $my_progname
#   as UNIX root.
#
unknown's avatar
unknown committed
640 641 642 643 644 645 646 647 648 649 650
# 7.A Start-up Manage Script for $my_progname
#
#   In the recent MySQL distributions you can find a file called
#   mysqld_multi.server.sh. It is a wrapper for $my_progname. This can
#   be used to start and stop multiple servers during boot and shutdown.
#
#   You can place the file in /etc/init.d/mysqld_multi.server.sh and
#   make the needed symbolic links to it from various run levels
#   (as per Linux/Unix standard). You may even replace the
#   /etc/init.d/mysql.server script with it.
#
651
#   Before using, you must create a my.cnf file either in @sysconfdir@/my.cnf
unknown's avatar
unknown committed
652 653 654 655 656
#   or /root/.my.cnf and add the [mysqld_multi] and [mysqld#] groups.
#
#   The script can be found from support-files/mysqld_multi.server.sh
#   in MySQL distribution. (Verify the script before using)
#
657

658
[mysqld_multi]
unknown's avatar
unknown committed
659
mysqld     = @bindir@/mysqld_safe
unknown's avatar
unknown committed
660
mysqladmin = @bindir@/mysqladmin
661 662
user       = multi_admin
password   = my_password
663 664 665 666

[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3307
unknown's avatar
unknown committed
667 668 669
pid-file   = @localstatedir@2/hostname.pid2
datadir    = @localstatedir@2
language   = @datadir@/mysql/english
670
user       = unix_user1
671 672

[mysqld3]
673 674 675
mysqld     = /path/to/safe_mysqld/safe_mysqld
ledir      = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin/mysqladmin
676 677
socket     = /tmp/mysql.sock3
port       = 3308
unknown's avatar
unknown committed
678 679 680
pid-file   = @localstatedir@3/hostname.pid3
datadir    = @localstatedir@3
language   = @datadir@/mysql/swedish
681
user       = unix_user2
682 683 684 685

[mysqld4]
socket     = /tmp/mysql.sock4
port       = 3309
unknown's avatar
unknown committed
686 687 688
pid-file   = @localstatedir@4/hostname.pid4
datadir    = @localstatedir@4
language   = @datadir@/mysql/estonia
689
user       = unix_user3
unknown's avatar
unknown committed
690
 
691 692 693
[mysqld6]
socket     = /tmp/mysql.sock6
port       = 3311
unknown's avatar
unknown committed
694 695 696
pid-file   = @localstatedir@6/hostname.pid6
datadir    = @localstatedir@6
language   = @datadir@/mysql/japanese
697
user       = unix_user4
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
EOF
  exit(0);
}

####
#### usage
####

sub usage
{
  print <<EOF;
$my_progname version $VER by Jani Tolonen

Description:
$my_progname can be used to start, or stop any number of separate
mysqld processes running in different TCP/IP ports and UNIX sockets.

715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
$my_progname can read group [mysqld_multi] from my.cnf file. You may
want to put options mysqld=... and mysqladmin=... there.  Since
version 2.10 these options can also be given under groups [mysqld#],
which gives more control over different versions.  One can have the
default mysqld and mysqladmin under group [mysqld_multi], but this is
not mandatory. Please note that if mysqld or mysqladmin is missing
from both [mysqld_multi] and [mysqld#], a group that is tried to be
used, $my_progname will abort with an error.

$my_progname will search for groups named [mysqld#] from my.cnf (or
the given --config-file=...), where '#' can be any positive integer
starting from 1. These groups should be the same as the regular
[mysqld] group, but with those port, socket and any other options
that are to be used with each separate mysqld process. The number
in the group name has another function; it can be used for starting,
stopping, or reporting any specific mysqld server.
731 732 733 734

Usage: $my_progname [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
or     $my_progname [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]

735 736 737 738 739 740
The GNR means the group number. You can start, stop or report any GNR,
or several of them at the same time. (See --example) The GNRs list can
be comma separated or a dash combined. The latter means that all the
GNRs between GNR1-GNR2 will be affected. Without GNR argument all the
groups found will either be started, stopped, or reported. Note that
syntax for specifying GNRs must appear without spaces.
741 742

Options:
743 744 745 746 747 748 749 750 751 752

These options must be given before any others:
--no-defaults      Do not read any defaults file
--defaults-file=...  Read only this configuration file, do not read the
                   standard system-wide and user-specific files
--defaults-extra-file=...  Read this configuration file in addition to the
                   standard system-wide and user-specific files
Using:  @{[join ' ', @defaults_options]}

--config-file=...  Deprecated, please use --defaults-extra-file instead
753
--example          Give an example of a config file with extra information.
754 755 756 757 758
--help             Print this help and exit.
--log=...          Log file. Full path to and the name for the log file. NOTE:
                   If the file exists, everything will be appended.
                   Using: $opt_log
--mysqladmin=...   mysqladmin binary to be used for a server shutdown.
759
                   Since version 2.10 this can be given within groups [mysqld#]
760
                   Using: $mysqladmin
unknown's avatar
unknown committed
761
--mysqld=...       mysqld binary to be used. Note that you can give mysqld_safe
762
                   to this option also. The options are passed to mysqld. Just
unknown's avatar
unknown committed
763
                   make sure you have mysqld in your PATH or fix mysqld_safe.
764
                   Using: $mysqld
765
                   Please note: Since mysqld_multi version 2.3 you can also
766 767
                   give this option inside groups [mysqld#] in ~/.my.cnf,
                   where '#' stands for an integer (number) of the group in
768
                   question. This will be recognised as a special option and
769 770
                   will not be passed to the mysqld. This will allow one to
                   start different mysqld versions with mysqld_multi.
771 772
--no-log           Print to stdout instead of the log file. By default the log
                   file is turned on.
773
--password=...     Password for mysqladmin user.
774
--silent           Disable warnings.
775 776 777 778 779
--tcp-ip           Connect to the MySQL server(s) via the TCP/IP port instead
                   of the UNIX socket. This affects stopping and reporting.
                   If a socket file is missing, the server may still be
                   running, but can be accessed only via the TCP/IP port.
                   By default connecting is done via the UNIX socket.
780
--user=...         mysqladmin user. Using: $opt_user
781
--verbose          Be more verbose.
782 783 784 785
--version          Print the version number and exit.
EOF
  exit(0);
}