⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqld_multi

📁 开启mysql的远程连接的方法 mysql-noinstall-5.1.6-alpha-win32.zip
💻
📖 第 1 页 / 共 2 页
字号:
    $tmp.= " -p'$pw'";  }  $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;}######## Find groups. Takes the valid group numbers as an argument, parses#### them, puts them in the ascending order, removes duplicates and#### returns the wanted groups accordingly.####sub find_groups{  my ($raw_gids) = @_;  my (@groups, @data, @tmp, $line, $i, $k, @pre_gids, @gids, @tmp2,      $prev_value);  # Read the lines from the config file to variable 'data'  if (defined($opt_config_file))  {    open(MY_CNF, "<$opt_config_file") && (@data=<MY_CNF>) && close(MY_CNF);  }  else  {    if (-f "/etc/my.cnf" && -r "/etc/my.cnf")    {      open(MY_CNF, "</etc/my.cnf") && (@tmp=<MY_CNF>) && close(MY_CNF);    }    for ($i = 0; ($line = shift @tmp); $i++)    {      $data[$i] = $line;    }    if (defined($ENV{MYSQL_HOME}) && -f "$ENV{MYSQL_HOME}/my.cnf" &&	-r "$ENV{MYSQL_HOME}/my.cnf")    {      open(MY_CNF, "<$ENV{MYSQL_HOME}/my.cnf") && (@tmp=<MY_CNF>) &&      close(MY_CNF);    }    for (; ($line = shift @tmp); $i++)    {      $data[$i] = $line;    }    if (-f "$homedir/.my.cnf" && -r "$homedir/.my.cnf")    {      open(MY_CNF, "<$homedir/.my.cnf") && (@tmp=<MY_CNF>) && close(MY_CNF);    }    for (; ($line = shift @tmp); $i++)    {      $data[$i] = $line;    }  }  chop @data;  # Make a list of the wanted group ids  if (defined($raw_gids))  {    @pre_gids = split(',', $raw_gids);  }  if (defined($raw_gids))  {    for ($i = 0, $j = 0; defined($pre_gids[$i]); $i++)    {      if ($pre_gids[$i] =~ m/^(\d+)$/)      {	$gids[$j] = $1;	$j++;      }      elsif ($pre_gids[$i] =~ m/^(\d+)(\-)(\d+)$/)      {	for ($k = $1; $k <= $3; $k++)	{	  $gids[$j] = $k;	  $j++;	}      }      else      {	print "ABORT: Bad GNR: $pre_gids[$i] See $my_progname --help\n";	exit(1);      }    }  }  # Sort the list of gids numerically in ascending order  @gids = sort {$a <=> $b} @gids;  # Remove non-positive integers and duplicates  for ($i = 0, $j = 0; defined($gids[$i]); $i++)  {    next if ($gids[$i] <= 0);    if (!$i || $prev_value != $gids[$i])    {      $tmp2[$j] = $gids[$i];      $j++;    }    $prev_value = $gids[$i];  }  @gids = @tmp2;  # Find and return the wanted groups  for ($i = 0, $j = 0; defined($data[$i]); $i++)  {    if ($data[$i] =~ m/^(\s*\[\s*)(mysqld)(\d+)(\s*\]\s*)$/)    {      if (defined($raw_gids))      {	for ($k = 0; defined($gids[$k]); $k++)	{	  if ($gids[$k] == $3)	  {	    $groups[$j] = $2 . $3;	    $j++;	  }	}      }      else      {	$groups[$j] = $2 . $3;	$j++;      }    }  }  return @groups;}######## w2log: Write to a logfile.#### 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)  {    open (FROMFILE, "<$msg") && (@data=<FROMFILE>) &&      close(FROMFILE)	or die "FATAL: w2log: Couldn't open file: $msg\n";    foreach my $line (@data)    {      print LOGFILE "$line";    }  }  else  {    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;# 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## 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#   - Heavily media (disk) bound#   - Relies on the system (external) file locking#   - Is not applicable with all table types. (Such as InnoDB)#     Trying so will end up with undesirable results.## 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.## 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.##   Before using, you must create a my.cnf file either in /etc/my.cnf#   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)#[mysqld_multi]mysqld     = /usr/local/bin/mysqld_safemysqladmin = /usr/local/bin/mysqladminuser       = multi_adminpassword   = my_password[mysqld2]socket     = /tmp/mysql.sock2port       = 3307pid-file   = /usr/local/var2/hostname.pid2datadir    = /usr/local/var2language   = /usr/local/share/mysql/englishuser       = unix_user1[mysqld3]mysqld     = /path/to/safe_mysqld/safe_mysqldledir      = /path/to/mysqld-binary/mysqladmin = /path/to/mysqladmin/mysqladminsocket     = /tmp/mysql.sock3port       = 3308pid-file   = /usr/local/var3/hostname.pid3datadir    = /usr/local/var3language   = /usr/local/share/mysql/swedishuser       = unix_user2[mysqld4]socket     = /tmp/mysql.sock4port       = 3309pid-file   = /usr/local/var4/hostname.pid4datadir    = /usr/local/var4language   = /usr/local/share/mysql/estoniauser       = unix_user3 [mysqld6]socket     = /tmp/mysql.sock6port       = 3311pid-file   = /usr/local/var6/hostname.pid6datadir    = /usr/local/var6language   = /usr/local/share/mysql/japaneseuser       = unix_user4EOF  exit(0);}######## usage####sub usage{  print <<EOF;$my_progname version $VER by Jani TolonenDescription:$my_progname can be used to start, or stop any number of separatemysqld processes running in different TCP/IP ports and UNIX sockets.$my_progname can read group [mysqld_multi] from my.cnf file. You maywant to put options mysqld=... and mysqladmin=... there.  Sinceversion 2.10 these options can also be given under groups [mysqld#],which gives more control over different versions.  One can have thedefault mysqld and mysqladmin under group [mysqld_multi], but this isnot mandatory. Please note that if mysqld or mysqladmin is missingfrom both [mysqld_multi] and [mysqld#], a group that is tried to beused, $my_progname will abort with an error.$my_progname will search for groups named [mysqld#] from my.cnf (orthe given --config-file=...), where '#' can be any positive integerstarting from 1. These groups should be the same as the regular[mysqld] group, but with those port, socket and any other optionsthat are to be used with each separate mysqld process. The numberin the group name has another function; it can be used for starting,stopping, or reporting any specific mysqld server.Usage: $my_progname [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]or     $my_progname [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]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 canbe comma separated or a dash combined. The latter means that all theGNRs between GNR1-GNR2 will be affected. Without GNR argument all thegroups found will either be started, stopped, or reported. Note thatsyntax for specifying GNRs must appear without spaces.Options:--config-file=...  Alternative config file.                   Using: $opt_config_file--example          Give an example of a config file with extra information.--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.                   Since version 2.10 this can be given within groups [mysqld#]                   Using: $mysqladmin--mysqld=...       mysqld binary to be used. Note that you can give mysqld_safe                   to this option also. The options are passed to mysqld. Just                   make sure you have mysqld in your PATH or fix mysqld_safe.                   Using: $mysqld                   Please note: Since mysqld_multi version 2.3 you can also                   give this option inside groups [mysqld#] in ~/.my.cnf,                   where '#' stands for an integer (number) of the group in                   question. This will be recognised as a special option and                   will not be passed to the mysqld. This will allow one to                   start different mysqld versions with mysqld_multi.--no-log           Print to stdout instead of the log file. By default the log                   file is turned on.--password=...     Password for mysqladmin user.--silent           Disable warnings.--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.--user=...         mysqladmin user. Using: $opt_user--verbose          Be more verbose.--version          Print the version number and exit.EOF  exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -