mirror of
https://gitlab.com/2009scape/singleplayer/linux.git
synced 2026-08-01 14:39:15 -06:00
Added v1.0
This commit is contained in:
parent
5bbf0452e2
commit
73d50eda34
679 changed files with 357432 additions and 0 deletions
BIN
database/bin/aria_chk
Executable file
BIN
database/bin/aria_chk
Executable file
Binary file not shown.
BIN
database/bin/aria_dump_log
Executable file
BIN
database/bin/aria_dump_log
Executable file
Binary file not shown.
BIN
database/bin/aria_ftdump
Executable file
BIN
database/bin/aria_ftdump
Executable file
Binary file not shown.
BIN
database/bin/aria_pack
Executable file
BIN
database/bin/aria_pack
Executable file
Binary file not shown.
BIN
database/bin/aria_read_log
Executable file
BIN
database/bin/aria_read_log
Executable file
Binary file not shown.
BIN
database/bin/innochecksum
Executable file
BIN
database/bin/innochecksum
Executable file
Binary file not shown.
19
database/bin/msql2mysql
Executable file
19
database/bin/msql2mysql
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 1979-2007 MySQL AB
|
||||
# Use is subject to license terms
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to the
|
||||
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston
|
||||
# MA 02110-1335 USA.
|
||||
|
||||
/usr/local/mysql/bin/replace msqlConnect mysql_connect msqlListDBs mysql_list_dbs msqlNumRows mysql_num_rows msqlFetchRow mysql_fetch_row msqlFetchField mysql_fetch_field msqlFreeResult mysql_free_result msqlListFields mysql_list_fields msqlListTables mysql_list_tables msqlErrMsg 'mysql_error(mysql)' msqlStoreResult mysql_store_result msqlQuery mysql_query msqlField mysql_field msqlSelect mysql_select msqlSelectDB mysql_select_db msqlNumFields mysql_num_fields msqlClose mysql_close msqlDataSeek mysql_data_seek m_field MYSQL_FIELD m_result MYSQL_RES m_row MYSQL_ROW msql mysql mSQL mySQL MSQL MYSQL msqlCreateDB mysql_create_db msqlDropDB mysql_drop_db msqlFieldSeek mysql_field_seek -- $*
|
||||
BIN
database/bin/my_print_defaults
Executable file
BIN
database/bin/my_print_defaults
Executable file
Binary file not shown.
BIN
database/bin/myisam_ftdump
Executable file
BIN
database/bin/myisam_ftdump
Executable file
Binary file not shown.
BIN
database/bin/myisamchk
Executable file
BIN
database/bin/myisamchk
Executable file
Binary file not shown.
BIN
database/bin/myisamlog
Executable file
BIN
database/bin/myisamlog
Executable file
Binary file not shown.
BIN
database/bin/myisampack
Executable file
BIN
database/bin/myisampack
Executable file
Binary file not shown.
BIN
database/bin/mysql
Executable file
BIN
database/bin/mysql
Executable file
Binary file not shown.
BIN
database/bin/mysql_client_test
Executable file
BIN
database/bin/mysql_client_test
Executable file
Binary file not shown.
BIN
database/bin/mysql_client_test_embedded
Executable file
BIN
database/bin/mysql_client_test_embedded
Executable file
Binary file not shown.
222
database/bin/mysql_config
Executable file
222
database/bin/mysql_config
Executable file
|
|
@ -0,0 +1,222 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
# This script reports various configuration settings that may be needed
|
||||
# when using the MySQL client library.
|
||||
|
||||
which ()
|
||||
{
|
||||
IFS="${IFS= }"; save_ifs="$IFS"; IFS=':'
|
||||
for file
|
||||
do
|
||||
for dir in $PATH
|
||||
do
|
||||
if test -f $dir/$file
|
||||
then
|
||||
echo "$dir/$file"
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
echo "which: no $file in ($PATH)"
|
||||
exit 1
|
||||
done
|
||||
IFS="$save_ifs"
|
||||
}
|
||||
|
||||
#
|
||||
# If we can find the given directory relatively to where mysql_config is
|
||||
# we should use this instead of the incompiled one.
|
||||
# This is to ensure that this script also works with the binary MySQL
|
||||
# version
|
||||
|
||||
fix_path ()
|
||||
{
|
||||
var=$1
|
||||
shift
|
||||
for filename
|
||||
do
|
||||
path=$basedir/$filename
|
||||
if [ -d "$path" ] ;
|
||||
then
|
||||
eval "$var"=$path
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
get_full_path ()
|
||||
{
|
||||
file=$1
|
||||
|
||||
# if the file is a symlink, try to resolve it
|
||||
if [ -h $file ];
|
||||
then
|
||||
file=`ls -l $file | awk '{ print $NF }'`
|
||||
fi
|
||||
|
||||
case $file in
|
||||
/*) echo "$file";;
|
||||
*/*) tmp=`pwd`/$file; echo $tmp | sed -e 's;/\./;/;' ;;
|
||||
*) which $file ;;
|
||||
esac
|
||||
}
|
||||
|
||||
me=`get_full_path $0`
|
||||
|
||||
# Script might have been renamed but assume mysql_<something>config<something>
|
||||
basedir=`echo $me | sed -e 's;/bin/mysql_.*config.*;;'`
|
||||
|
||||
ldata='/usr/local/mysql/data'
|
||||
execdir='/usr/local/mysql/bin'
|
||||
bindir='/usr/local/mysql/bin'
|
||||
|
||||
# If installed, search for the compiled in directory first (might be "lib64")
|
||||
pkglibdir='/usr/local/mysql/lib'
|
||||
pkglibdir_rel=`echo $pkglibdir | sed -e "s;^$basedir/;;"`
|
||||
fix_path pkglibdir $pkglibdir_rel lib/mysql lib
|
||||
|
||||
plugindir='/usr/local/mysql/lib/plugin'
|
||||
plugindir_rel=`echo $plugindir | sed -e "s;^$basedir/;;"`
|
||||
fix_path plugindir $plugindir_rel lib/mysql/plugin lib/plugin
|
||||
|
||||
pkgincludedir='/usr/local/mysql/include/mysql'
|
||||
fix_path pkgincludedir include/mysql
|
||||
|
||||
version='5.5.68'
|
||||
socket='/tmp/mysql.sock'
|
||||
ldflags=''
|
||||
|
||||
if [ 0 -eq 0 ]; then
|
||||
port=0
|
||||
else
|
||||
port=3306
|
||||
fi
|
||||
|
||||
# Create options
|
||||
# We intentionally add a space to the beginning and end of lib strings, simplifies replace later
|
||||
libs=" $ldflags -L$pkglibdir -lmysqlclient -lpthread -lm -lrt -ldl "
|
||||
libs="$libs "
|
||||
libs_r=" $ldflags -L$pkglibdir -lmysqlclient_r -lpthread -lm -lrt -ldl "
|
||||
embedded_libs=" $ldflags -L$pkglibdir -lmysqld "
|
||||
|
||||
if [ -r "$pkglibdir/libmygcc.a" ]; then
|
||||
# When linking against the static library with a different version of GCC
|
||||
# from what was used to compile the library, some symbols may not be defined
|
||||
# automatically. We package the libmygcc.a from the build host, to provide
|
||||
# definitions for those. Bugs 4921, 19561, 19817, 21158, etc.
|
||||
libs="$libs -lmygcc "
|
||||
libs_r="$libs_r -lmygcc "
|
||||
embedded_libs="$embedded_libs -lmygcc "
|
||||
fi
|
||||
|
||||
include="-I$pkgincludedir"
|
||||
if [ "$basedir" != "/usr" ]; then
|
||||
include="$include -I$pkgincludedir/.."
|
||||
fi
|
||||
cflags="$include " #note: end space!
|
||||
|
||||
# Remove some options that a client doesn't have to care about
|
||||
# FIXME until we have a --cxxflags, we need to remove -Xa
|
||||
# and -xstrconst to make --cflags usable for Sun Forte C++
|
||||
# FIXME until we have a --cxxflags, we need to remove -AC99
|
||||
# to make --cflags usable for HP C++ (aCC)
|
||||
for remove in DDBUG_OFF DSAFE_MUTEX DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS \
|
||||
DEXTRA_DEBUG DHAVE_valgrind O 'O[0-9]' 'xO[0-9]' 'W[-A-Za-z]*' \
|
||||
'mtune=[-A-Za-z0-9]*' 'mcpu=[-A-Za-z0-9]*' 'march=[-A-Za-z0-9]*' \
|
||||
Xa xstrconst "xc99=none" AC99 'W[-A-Za-z]*=[-A-Za-z0-9]*' \
|
||||
unroll2 ip mp restrict
|
||||
do
|
||||
# The first option we might strip will always have a space before it because
|
||||
# we set -I$pkgincludedir as the first option
|
||||
cflags=`echo "$cflags"|sed -e ':again' -e "s/ -$remove */ /g" -e 't again'`
|
||||
done
|
||||
cflags=`echo "$cflags"|sed -e 's/ *\$//'`
|
||||
|
||||
# Same for --libs(_r)
|
||||
for remove in lmtmalloc static-libcxa i-static static-intel
|
||||
do
|
||||
# We know the strings starts with a space
|
||||
libs=`echo "$libs"|sed -e "s/ -$remove */ /g"`
|
||||
libs_r=`echo "$libs_r"|sed -e "s/ -$remove */ /g"`
|
||||
embedded_libs=`echo "$embedded_libs"|sed -e "s/ -$remove */ /g"`
|
||||
done
|
||||
|
||||
# Strip trailing and ending space if any, and '+' (FIXME why?)
|
||||
libs=`echo "$libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
|
||||
libs_r=`echo "$libs_r" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
|
||||
embedded_libs=`echo "$embedded_libs" | sed -e 's; \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
|
||||
|
||||
usage () {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTIONS]
|
||||
Options:
|
||||
--cflags [$cflags]
|
||||
--include [$include]
|
||||
--libs [$libs]
|
||||
--libs_r [$libs_r]
|
||||
--plugindir [$plugindir]
|
||||
--socket [$socket]
|
||||
--port [$port]
|
||||
--version [$version]
|
||||
--libmysqld-libs [$embedded_libs]
|
||||
--variable=VAR VAR is one of:
|
||||
pkgincludedir [$pkgincludedir]
|
||||
pkglibdir [$pkglibdir]
|
||||
plugindir [$plugindir]
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
if test $# -le 0; then usage; fi
|
||||
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
--cflags) echo "$cflags" ;;
|
||||
--include) echo "$include" ;;
|
||||
--libs) echo "$libs" ;;
|
||||
--libs_r) echo "$libs_r" ;;
|
||||
--plugindir) echo "$plugindir" ;;
|
||||
--socket) echo "$socket" ;;
|
||||
--port) echo "$port" ;;
|
||||
--version) echo "$version" ;;
|
||||
--embedded-libs | --embedded | --libmysqld-libs) echo "$embedded_libs" ;;
|
||||
--variable=*)
|
||||
var=`echo "$1" | sed 's,^[^=]*=,,'`
|
||||
case "$var" in
|
||||
pkgincludedir) echo "$pkgincludedir" ;;
|
||||
pkglibdir) echo "$pkglibdir" ;;
|
||||
plugindir) echo "$plugindir" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
#echo "ldata: '"$ldata"'"
|
||||
#echo "execdir: '"$execdir"'"
|
||||
#echo "bindir: '"$bindir"'"
|
||||
#echo "pkglibdir: '"$pkglibdir"'"
|
||||
#echo "pkgincludedir: '"$pkgincludedir"'"
|
||||
#echo "version: '"$version"'"
|
||||
#echo "socket: '"$socket"'"
|
||||
#echo "port: '"$port"'"
|
||||
#echo "ldflags: '"$ldflags"'"
|
||||
#echo "client_libs: '"$client_libs"'"
|
||||
|
||||
exit 0
|
||||
167
database/bin/mysql_convert_table_format
Executable file
167
database/bin/mysql_convert_table_format
Executable file
|
|
@ -0,0 +1,167 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
# Convert given tables in a database to MYISAM
|
||||
|
||||
use DBI;
|
||||
use Getopt::Long;
|
||||
|
||||
$opt_help=$opt_version=$opt_verbose=$opt_force=0;
|
||||
$opt_user=$opt_database=$opt_password=undef;
|
||||
$opt_host="localhost";
|
||||
$opt_socket="";
|
||||
$opt_engine="MYISAM";
|
||||
$opt_port=0;
|
||||
$exit_status=0;
|
||||
|
||||
GetOptions(
|
||||
"e|engine|type=s" => \$opt_engine,
|
||||
"f|force" => \$opt_force,
|
||||
"help|?" => \$opt_help,
|
||||
"h|host=s" => \$opt_host,
|
||||
"p|password=s" => \$opt_password,
|
||||
"u|user=s" => \$opt_user,
|
||||
"v|verbose" => \$opt_verbose,
|
||||
"V|version" => \$opt_version,
|
||||
"S|socket=s" => \$opt_socket,
|
||||
"P|port=i" => \$opt_port
|
||||
) || usage(0);
|
||||
|
||||
usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
|
||||
|
||||
$opt_database=shift(@ARGV);
|
||||
|
||||
if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE))
|
||||
{
|
||||
print "Converting to '$opt_engine' would delete your data; aborting\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$connect_opt="";
|
||||
if ($opt_port)
|
||||
{
|
||||
$connect_opt.= ";port=$opt_port";
|
||||
}
|
||||
if (length($opt_socket))
|
||||
{
|
||||
$connect_opt.=";mysql_socket=$opt_socket";
|
||||
}
|
||||
|
||||
$dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt",
|
||||
$opt_user,
|
||||
$opt_password,
|
||||
{ PrintError => 0})
|
||||
|| die "Can't connect to database $opt_database: $DBI::errstr\n";
|
||||
|
||||
my @tables;
|
||||
|
||||
push(@ARGV, "%") if(!@ARGV);
|
||||
|
||||
foreach $pattern (@ARGV)
|
||||
{
|
||||
my ($sth,$row);
|
||||
$sth=$dbh->prepare("SHOW TABLES LIKE ?");
|
||||
$rv= $sth->execute($pattern);
|
||||
if(!int($rv))
|
||||
{
|
||||
warn "Can't get tables matching '$pattern' from $opt_database; $DBI::errstr\n";
|
||||
exit(1) unless $opt_force;
|
||||
}
|
||||
while (($row = $sth->fetchrow_arrayref))
|
||||
{
|
||||
push(@tables, $row->[0]);
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
print "Converting tables:\n" if ($opt_verbose);
|
||||
foreach $table (@tables)
|
||||
{
|
||||
my ($sth,$row);
|
||||
|
||||
# Check if table is already converted
|
||||
$sth=$dbh->prepare("show table status like '$table'");
|
||||
if ($sth->execute && ($row = $sth->fetchrow_arrayref))
|
||||
{
|
||||
if (uc($row->[1]) eq uc($opt_engine))
|
||||
{
|
||||
print "$table already uses the '$opt_engine' engine; Ignored\n";
|
||||
next;
|
||||
}
|
||||
}
|
||||
print "converting $table\n" if ($opt_verbose);
|
||||
$table=~ s/`/``/g;
|
||||
if (!$dbh->do("ALTER TABLE `$table` ENGINE=$opt_engine"))
|
||||
{
|
||||
print STDERR "Can't convert $table: Error $DBI::errstr\n";
|
||||
exit(1) if (!$opt_force);
|
||||
$exit_status=1;
|
||||
}
|
||||
}
|
||||
|
||||
$dbh->disconnect;
|
||||
exit($exit_status);
|
||||
|
||||
|
||||
sub usage
|
||||
{
|
||||
my($version)=shift;
|
||||
print "$0 version 1.1\n";
|
||||
exit(0) if ($version);
|
||||
|
||||
print <<EOF;
|
||||
|
||||
Conversion of a MySQL tables to other storage engines
|
||||
|
||||
Usage: $0 database [table[ table ...]]
|
||||
If no tables has been specifed, all tables in the database will be converted.
|
||||
You can also use wildcards, ie "my%"
|
||||
|
||||
The following options are available:
|
||||
|
||||
-f, --force
|
||||
Continue even if there is some error.
|
||||
|
||||
-?, --help
|
||||
Shows this help
|
||||
|
||||
-e, --engine=ENGINE
|
||||
Converts tables to the given storage engine (Default: $opt_engine)
|
||||
|
||||
-h, --host=HOST
|
||||
Host name where the database server is located. (Default: $opt_host)
|
||||
|
||||
-p, --password=PASSWORD
|
||||
Password for the current user.
|
||||
|
||||
-P, --port=PORT
|
||||
TCP/IP port to connect to if host is not "localhost".
|
||||
|
||||
-S, --socket=SOCKET
|
||||
Socket to connect with.
|
||||
|
||||
-u, --user=USER
|
||||
User name to log into the SQL server.
|
||||
|
||||
-v, --verbose
|
||||
This is a test specific option that is only used when debugging a test.
|
||||
Print more information about what is going on.
|
||||
|
||||
-V, --version
|
||||
Shows the version of this program.
|
||||
EOF
|
||||
exit(1);
|
||||
}
|
||||
BIN
database/bin/mysql_embedded
Executable file
BIN
database/bin/mysql_embedded
Executable file
Binary file not shown.
159
database/bin/mysql_find_rows
Executable file
159
database/bin/mysql_find_rows
Executable file
|
|
@ -0,0 +1,159 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
$version="1.02";
|
||||
|
||||
use Getopt::Long;
|
||||
|
||||
$opt_help=$opt_Information=$opt_skip_use_db=0;
|
||||
$opt_regexp=$opt_dbregexp=".*";
|
||||
$opt_start_row=1; $opt_rows=9999999999;
|
||||
|
||||
GetOptions("Information","help","regexp=s","start_row=i","rows=i",
|
||||
"dbregexp=s", "skip-use-db")
|
||||
|| usage();
|
||||
usage() if ($opt_help || $opt_Information);
|
||||
|
||||
$query=$search=$database=$set=""; $eoq=0;
|
||||
while (<>)
|
||||
{
|
||||
next if (length($query) == 0 && /^\#/); # Skip comments
|
||||
$query.=search($_);
|
||||
if ($eoq)
|
||||
{
|
||||
if ($query =~ /^use /i || $query =~ /^SET / ||
|
||||
($query =~ /$opt_regexp/o && $database =~ /$opt_dbregexp/o))
|
||||
{
|
||||
if ($opt_skip_use_db && $query =~ /^use /i)
|
||||
{
|
||||
$query="";
|
||||
next;
|
||||
}
|
||||
if ($opt_start_row <= 1)
|
||||
{
|
||||
if ($database)
|
||||
{
|
||||
print $database, $set;
|
||||
$database=$set="";
|
||||
}
|
||||
print $query;
|
||||
last if (--$opt_rows == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt_start_row--;
|
||||
if ($query =~ /^use /)
|
||||
{
|
||||
$database=$query;
|
||||
$set="";
|
||||
}
|
||||
elsif ($query =~ /^SET/)
|
||||
{
|
||||
$set=$query;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set="";
|
||||
}
|
||||
}
|
||||
}
|
||||
$query=""; $search=""; $eoq=0;
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
sub search
|
||||
{
|
||||
my($row)=shift;
|
||||
my($i);
|
||||
|
||||
for ($i=0 ; $i < length($row) ; $i++)
|
||||
{
|
||||
if (length($search))
|
||||
{
|
||||
if (length($search) > 1)
|
||||
{ # Comment
|
||||
next if (substr($row,$i,length($search)) ne $search);
|
||||
$i+=length($search)-1;
|
||||
$search="";
|
||||
}
|
||||
elsif (substr($row,$i,1) eq '\\') # Escaped char in string
|
||||
{
|
||||
$i++;
|
||||
}
|
||||
elsif (substr($row,$i,1) eq $search)
|
||||
{
|
||||
if (substr($row,$i+1,1) eq $search) # Double " or '
|
||||
{
|
||||
$i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$search="";
|
||||
}
|
||||
}
|
||||
next;
|
||||
}
|
||||
if (substr($row,$i,2) eq '/*') # Comment
|
||||
{
|
||||
$search="*/";
|
||||
$i++;
|
||||
}
|
||||
elsif (substr($row,$i,1) eq "'" || substr($row,$i,1) eq '"')
|
||||
{
|
||||
$search=substr($row,$i,1);
|
||||
}
|
||||
}
|
||||
$eoq=1 if (!length($search) && $row =~ /;\s*$/);
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
sub usage
|
||||
{
|
||||
print <<EOF;
|
||||
$0 Ver $version
|
||||
|
||||
Prints all SQL queries that matches a regexp or contains a 'use
|
||||
database' or 'set ..' command to stdout. A SQL query may contain
|
||||
newlines. This is useful to find things in a MySQL update log.
|
||||
|
||||
$0 takes the following options:
|
||||
|
||||
--help or --Information
|
||||
Shows this help
|
||||
|
||||
--regexp=#
|
||||
Print queries that matches this.
|
||||
|
||||
--start_row=#
|
||||
Start output from this row (first row = 1)
|
||||
|
||||
--skip-use-db
|
||||
Don\'t include \'use database\' commands in the output.
|
||||
|
||||
--rows=#
|
||||
Quit after this many rows.
|
||||
|
||||
Example:
|
||||
|
||||
$0 --regexp "problem_table" < update.log
|
||||
|
||||
$0 --regexp "problem_table" update-log.1 update-log.2
|
||||
EOF
|
||||
exit(0);
|
||||
}
|
||||
34
database/bin/mysql_fix_extensions
Executable file
34
database/bin/mysql_fix_extensions
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; version 2
|
||||
# of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1335 USA
|
||||
|
||||
# This is a utility for MySQL. It is not needed by any standard part
|
||||
# of MySQL.
|
||||
|
||||
# Usage: mysql_fix_extentions datadir
|
||||
# does not work with RAID, with InnoDB or BDB tables
|
||||
# makes .frm lowercase and .MYI/MYD/ISM/ISD uppercase
|
||||
# useful when datafiles are copied from windows
|
||||
|
||||
die "Usage: $0 datadir\n" unless -d $ARGV[0];
|
||||
|
||||
for $a (<$ARGV[0]/*/*.*>) { $_=$a;
|
||||
s/\.frm$/.frm/i;
|
||||
s/\.(is[md]|my[id])$/\U$&/i;
|
||||
rename ($a, $_) || warn "Cannot rename $a => $_ : $!";
|
||||
}
|
||||
BIN
database/bin/mysql_plugin
Executable file
BIN
database/bin/mysql_plugin
Executable file
Binary file not shown.
535
database/bin/mysql_secure_installation
Executable file
535
database/bin/mysql_secure_installation
Executable file
|
|
@ -0,0 +1,535 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
config=".my.cnf.$$"
|
||||
command=".mysql.$$"
|
||||
|
||||
trap "interrupt" 1 2 3 6 15
|
||||
|
||||
rootpass=""
|
||||
echo_n=
|
||||
echo_c=
|
||||
basedir=
|
||||
bindir=
|
||||
|
||||
parse_arg()
|
||||
{
|
||||
echo "$1" | sed -e 's/^[^=]*=//'
|
||||
}
|
||||
|
||||
parse_arguments()
|
||||
{
|
||||
# We only need to pass arguments through to the server if we don't
|
||||
# handle them here. So, we collect unrecognized options (passed on
|
||||
# the command line) into the args variable.
|
||||
pick_args=
|
||||
if test "$1" = PICK-ARGS-FROM-ARGV
|
||||
then
|
||||
pick_args=1
|
||||
shift
|
||||
fi
|
||||
|
||||
for arg
|
||||
do
|
||||
case "$arg" in
|
||||
--basedir=*) basedir=`parse_arg "$arg"` ;;
|
||||
--no-defaults|--defaults-file=*|--defaults-extra-file=*)
|
||||
defaults="$arg" ;;
|
||||
*)
|
||||
if test -n "$pick_args"
|
||||
then
|
||||
# This sed command makes sure that any special chars are quoted,
|
||||
# so the arg gets passed exactly to the server.
|
||||
# XXX: This is broken; true fix requires using eval and proper
|
||||
# quoting of every single arg ($basedir, $ldata, etc.)
|
||||
#args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'`
|
||||
args="$args $arg"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Try to find a specific file within --basedir which can either be a binary
|
||||
# release or installed source directory and return the path.
|
||||
find_in_basedir()
|
||||
{
|
||||
return_dir=0
|
||||
found=0
|
||||
case "$1" in
|
||||
--dir)
|
||||
return_dir=1; shift
|
||||
;;
|
||||
esac
|
||||
|
||||
file=$1; shift
|
||||
|
||||
for dir in "$@"
|
||||
do
|
||||
if test -f "$basedir/$dir/$file"
|
||||
then
|
||||
found=1
|
||||
if test $return_dir -eq 1
|
||||
then
|
||||
echo "$basedir/$dir"
|
||||
else
|
||||
echo "$basedir/$dir/$file"
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if test $found -eq 0
|
||||
then
|
||||
# Test if command is in PATH
|
||||
$file --no-defaults --version > /dev/null 2>&1
|
||||
status=$?
|
||||
if test $status -eq 0
|
||||
then
|
||||
echo $file
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cannot_find_file()
|
||||
{
|
||||
echo
|
||||
echo "FATAL ERROR: Could not find $1"
|
||||
|
||||
shift
|
||||
if test $# -ne 0
|
||||
then
|
||||
echo
|
||||
echo "The following directories were searched:"
|
||||
echo
|
||||
for dir in "$@"
|
||||
do
|
||||
echo " $dir"
|
||||
done
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "If you compiled from source, you need to run 'make install' to"
|
||||
echo "copy the software into the correct location ready for operation."
|
||||
echo
|
||||
echo "If you are using a binary release, you must either be at the top"
|
||||
echo "level of the extracted archive, or pass the --basedir option"
|
||||
echo "pointing to that location."
|
||||
echo
|
||||
}
|
||||
|
||||
# Ok, let's go. We first need to parse arguments which are required by
|
||||
# my_print_defaults so that we can execute it first, then later re-parse
|
||||
# the command line to add any extra bits that we need.
|
||||
parse_arguments PICK-ARGS-FROM-ARGV "$@"
|
||||
|
||||
#
|
||||
# We can now find my_print_defaults. This script supports:
|
||||
#
|
||||
# --srcdir=path pointing to compiled source tree
|
||||
# --basedir=path pointing to installed binary location
|
||||
#
|
||||
# or default to compiled-in locations.
|
||||
#
|
||||
|
||||
if test -n "$basedir"
|
||||
then
|
||||
print_defaults=`find_in_basedir my_print_defaults bin extra`
|
||||
echo "print: $print_defaults"
|
||||
if test -z "$print_defaults"
|
||||
then
|
||||
cannot_find_file my_print_defaults $basedir/bin $basedir/extra
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_defaults="/usr/local/mysql/bin/my_print_defaults"
|
||||
fi
|
||||
|
||||
if test ! -x "$print_defaults"
|
||||
then
|
||||
cannot_find_file "$print_defaults"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Now we can get arguments from the group [client] and [client-server]
|
||||
# in the my.cfg file, then re-run to merge with command line arguments.
|
||||
parse_arguments `$print_defaults $defaults client client-server client-mariadb`
|
||||
parse_arguments PICK-ARGS-FROM-ARGV "$@"
|
||||
|
||||
# Configure paths to support files
|
||||
if test -n "$basedir"
|
||||
then
|
||||
bindir="$basedir/bin"
|
||||
elif test -f "./bin/mysql"
|
||||
then
|
||||
bindir="./bin"
|
||||
else
|
||||
bindir="/usr/local/mysql/bin"
|
||||
fi
|
||||
|
||||
mysql_command=`find_in_basedir mysql $bindir`
|
||||
if test -z "$print_defaults"
|
||||
then
|
||||
cannot_find_file mysql $bindir
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set_echo_compat() {
|
||||
case `echo "testing\c"`,`echo -n testing` in
|
||||
*c*,-n*) echo_n= echo_c= ;;
|
||||
*c*,*) echo_n=-n echo_c= ;;
|
||||
*) echo_n= echo_c='\c' ;;
|
||||
esac
|
||||
}
|
||||
|
||||
validate_reply () {
|
||||
ret=0
|
||||
if [ -z "$1" ]; then
|
||||
reply=y
|
||||
return $ret
|
||||
fi
|
||||
case $1 in
|
||||
y|Y|yes|Yes|YES) reply=y ;;
|
||||
n|N|no|No|NO) reply=n ;;
|
||||
*) ret=1 ;;
|
||||
esac
|
||||
return $ret
|
||||
}
|
||||
|
||||
prepare() {
|
||||
touch $config $command
|
||||
chmod 600 $config $command
|
||||
}
|
||||
|
||||
do_query() {
|
||||
echo "$1" >$command
|
||||
#sed 's,^,> ,' < $command # Debugging
|
||||
$bindir/mysql --defaults-file=$config <$command
|
||||
return $?
|
||||
}
|
||||
|
||||
# Simple escape mechanism (\-escape any ' and \), suitable for two contexts:
|
||||
# - single-quoted SQL strings
|
||||
# - single-quoted option values on the right hand side of = in my.cnf
|
||||
#
|
||||
# These two contexts don't handle escapes identically. SQL strings allow
|
||||
# quoting any character (\C => C, for any C), but my.cnf parsing allows
|
||||
# quoting only \, ' or ". For example, password='a\b' quotes a 3-character
|
||||
# string in my.cnf, but a 2-character string in SQL.
|
||||
#
|
||||
# This simple escape works correctly in both places.
|
||||
basic_single_escape () {
|
||||
# The quoting on this sed command is a bit complex. Single-quoted strings
|
||||
# don't allow *any* escape mechanism, so they cannot contain a single
|
||||
# quote. The string sed gets (as argv[1]) is: s/\(['\]\)/\\\1/g
|
||||
#
|
||||
# Inside a character class, \ and ' are not special, so the ['\] character
|
||||
# class is balanced and contains two characters.
|
||||
echo "$1" | sed 's/\(['"'"'\]\)/\\\1/g'
|
||||
}
|
||||
|
||||
make_config() {
|
||||
echo "# mysql_secure_installation config file" >$config
|
||||
echo "[mysql]" >>$config
|
||||
echo "user=root" >>$config
|
||||
esc_pass=`basic_single_escape "$rootpass"`
|
||||
echo "password='$esc_pass'" >>$config
|
||||
#sed 's,^,> ,' < $config # Debugging
|
||||
}
|
||||
|
||||
get_root_password() {
|
||||
status=1
|
||||
while [ $status -eq 1 ]; do
|
||||
stty -echo
|
||||
echo $echo_n "Enter current password for root (enter for none): $echo_c"
|
||||
read password
|
||||
echo
|
||||
stty echo
|
||||
if [ "x$password" = "x" ]; then
|
||||
hadpass=0
|
||||
else
|
||||
hadpass=1
|
||||
fi
|
||||
rootpass=$password
|
||||
make_config
|
||||
do_query ""
|
||||
status=$?
|
||||
done
|
||||
echo "OK, successfully used password, moving on..."
|
||||
echo
|
||||
}
|
||||
|
||||
set_root_password() {
|
||||
stty -echo
|
||||
echo $echo_n "New password: $echo_c"
|
||||
read password1
|
||||
echo
|
||||
echo $echo_n "Re-enter new password: $echo_c"
|
||||
read password2
|
||||
echo
|
||||
stty echo
|
||||
|
||||
if [ "$password1" != "$password2" ]; then
|
||||
echo "Sorry, passwords do not match."
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$password1" = "" ]; then
|
||||
echo "Sorry, you can't use an empty password here."
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
|
||||
esc_pass=`basic_single_escape "$password1"`
|
||||
do_query "UPDATE mysql.user SET Password=PASSWORD('$esc_pass') WHERE User='root';"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Password updated successfully!"
|
||||
echo "Reloading privilege tables.."
|
||||
reload_privilege_tables
|
||||
if [ $? -eq 1 ]; then
|
||||
clean_and_exit
|
||||
fi
|
||||
echo
|
||||
rootpass=$password1
|
||||
make_config
|
||||
else
|
||||
echo "Password update failed!"
|
||||
clean_and_exit
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_anonymous_users() {
|
||||
do_query "DELETE FROM mysql.user WHERE User='';"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ... Success!"
|
||||
else
|
||||
echo " ... Failed!"
|
||||
clean_and_exit
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_remote_root() {
|
||||
do_query "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ... Success!"
|
||||
else
|
||||
echo " ... Failed!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_test_database() {
|
||||
echo " - Dropping test database..."
|
||||
do_query "DROP DATABASE IF EXISTS test;"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ... Success!"
|
||||
else
|
||||
echo " ... Failed! Not critical, keep moving..."
|
||||
fi
|
||||
|
||||
echo " - Removing privileges on test database..."
|
||||
do_query "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ... Success!"
|
||||
else
|
||||
echo " ... Failed! Not critical, keep moving..."
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
reload_privilege_tables() {
|
||||
do_query "FLUSH PRIVILEGES;"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ... Success!"
|
||||
return 0
|
||||
else
|
||||
echo " ... Failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
interrupt() {
|
||||
echo
|
||||
echo "Aborting!"
|
||||
echo
|
||||
cleanup
|
||||
stty echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo "Cleaning up..."
|
||||
rm -f $config $command
|
||||
}
|
||||
|
||||
# Remove the files before exiting.
|
||||
clean_and_exit() {
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The actual script starts here
|
||||
|
||||
prepare
|
||||
find_mysql_client
|
||||
set_echo_compat
|
||||
|
||||
echo
|
||||
echo "NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB"
|
||||
echo " SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!"
|
||||
echo
|
||||
echo "In order to log into MariaDB to secure it, we'll need the current"
|
||||
echo "password for the root user. If you've just installed MariaDB, and"
|
||||
echo "you haven't set the root password yet, the password will be blank,"
|
||||
echo "so you should just press enter here."
|
||||
echo
|
||||
|
||||
get_root_password
|
||||
|
||||
|
||||
#
|
||||
# Set the root password
|
||||
#
|
||||
|
||||
echo "Setting the root password ensures that nobody can log into the MariaDB"
|
||||
echo "root user without the proper authorisation."
|
||||
echo
|
||||
|
||||
while true ; do
|
||||
if [ $hadpass -eq 0 ]; then
|
||||
echo $echo_n "Set root password? [Y/n] $echo_c"
|
||||
else
|
||||
echo "You already have a root password set, so you can safely answer 'n'."
|
||||
echo
|
||||
echo $echo_n "Change the root password? [Y/n] $echo_c"
|
||||
fi
|
||||
read reply
|
||||
validate_reply $reply && break
|
||||
done
|
||||
|
||||
if [ "$reply" = "n" ]; then
|
||||
echo " ... skipping."
|
||||
else
|
||||
status=1
|
||||
while [ $status -eq 1 ]; do
|
||||
set_root_password
|
||||
status=$?
|
||||
done
|
||||
fi
|
||||
echo
|
||||
|
||||
|
||||
#
|
||||
# Remove anonymous users
|
||||
#
|
||||
|
||||
echo "By default, a MariaDB installation has an anonymous user, allowing anyone"
|
||||
echo "to log into MariaDB without having to have a user account created for"
|
||||
echo "them. This is intended only for testing, and to make the installation"
|
||||
echo "go a bit smoother. You should remove them before moving into a"
|
||||
echo "production environment."
|
||||
echo
|
||||
|
||||
while true ; do
|
||||
echo $echo_n "Remove anonymous users? [Y/n] $echo_c"
|
||||
read reply
|
||||
validate_reply $reply && break
|
||||
done
|
||||
if [ "$reply" = "n" ]; then
|
||||
echo " ... skipping."
|
||||
else
|
||||
remove_anonymous_users
|
||||
fi
|
||||
echo
|
||||
|
||||
|
||||
#
|
||||
# Disallow remote root login
|
||||
#
|
||||
|
||||
echo "Normally, root should only be allowed to connect from 'localhost'. This"
|
||||
echo "ensures that someone cannot guess at the root password from the network."
|
||||
echo
|
||||
while true ; do
|
||||
echo $echo_n "Disallow root login remotely? [Y/n] $echo_c"
|
||||
read reply
|
||||
validate_reply $reply && break
|
||||
done
|
||||
if [ "$reply" = "n" ]; then
|
||||
echo " ... skipping."
|
||||
else
|
||||
remove_remote_root
|
||||
fi
|
||||
echo
|
||||
|
||||
|
||||
#
|
||||
# Remove test database
|
||||
#
|
||||
|
||||
echo "By default, MariaDB comes with a database named 'test' that anyone can"
|
||||
echo "access. This is also intended only for testing, and should be removed"
|
||||
echo "before moving into a production environment."
|
||||
echo
|
||||
|
||||
while true ; do
|
||||
echo $echo_n "Remove test database and access to it? [Y/n] $echo_c"
|
||||
read reply
|
||||
validate_reply $reply && break
|
||||
done
|
||||
|
||||
if [ "$reply" = "n" ]; then
|
||||
echo " ... skipping."
|
||||
else
|
||||
remove_test_database
|
||||
fi
|
||||
echo
|
||||
|
||||
|
||||
#
|
||||
# Reload privilege tables
|
||||
#
|
||||
|
||||
echo "Reloading the privilege tables will ensure that all changes made so far"
|
||||
echo "will take effect immediately."
|
||||
echo
|
||||
|
||||
while true ; do
|
||||
echo $echo_n "Reload privilege tables now? [Y/n] $echo_c"
|
||||
read reply
|
||||
validate_reply $reply && break
|
||||
done
|
||||
|
||||
if [ "$reply" = "n" ]; then
|
||||
echo " ... skipping."
|
||||
else
|
||||
reload_privilege_tables
|
||||
fi
|
||||
echo
|
||||
|
||||
cleanup
|
||||
|
||||
echo
|
||||
echo "All done! If you've completed all of the above steps, your MariaDB"
|
||||
echo "installation should now be secure."
|
||||
echo
|
||||
echo "Thanks for using MariaDB!"
|
||||
672
database/bin/mysql_setpermission
Executable file
672
database/bin/mysql_setpermission
Executable file
|
|
@ -0,0 +1,672 @@
|
|||
#!/usr/bin/perl
|
||||
## Emacs, this is -*- perl -*- mode? :-)
|
||||
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; version 2
|
||||
# of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1335 USA
|
||||
|
||||
##
|
||||
## Permission setter for MySQL
|
||||
##
|
||||
## mady by Luuk de Boer (luuk@wxs.nl) 1998.
|
||||
## it's made under GPL ...:-))
|
||||
##
|
||||
##
|
||||
############################################################################
|
||||
## History
|
||||
##
|
||||
## 1.0 first start of the program
|
||||
## 1.1 some changes from monty and after that
|
||||
## initial release in mysql 3.22.10 (nov 1998)
|
||||
## 1.2 begin screen now in a loop + quit is using 0 instead of 9
|
||||
## after ideas of Paul DuBois.
|
||||
## 1.2a Add Grant, References, Index and Alter privilege handling (Monty)
|
||||
## 1.3 Applied patch provided by Martin Mokrejs <mmokrejs@natur.cuni.cz>
|
||||
## (General code cleanup, use the GRANT statement instead of updating
|
||||
## the privilege tables directly, added option to revoke privileges)
|
||||
## 1.4 Remove option 6 which attempted to erroneously grant global privileges
|
||||
|
||||
#### TODO
|
||||
#
|
||||
# empty ... suggestions ... mail them to me ...
|
||||
|
||||
|
||||
$version="1.4";
|
||||
|
||||
use DBI;
|
||||
use Getopt::Long;
|
||||
use strict;
|
||||
use vars qw($dbh $sth $hostname $opt_user $opt_password $opt_help $opt_host
|
||||
$opt_socket $opt_port $host $version);
|
||||
|
||||
my $sqlhost = "";
|
||||
my $user = "";
|
||||
|
||||
$dbh=$host=$opt_user= $opt_password= $opt_help= $opt_host= $opt_socket= "";
|
||||
$opt_port=0;
|
||||
|
||||
read_my_cnf(); # Read options from ~/.my.cnf
|
||||
|
||||
GetOptions("user=s","password=s","help","host=s","socket=s","port=i");
|
||||
|
||||
usage() if ($opt_help); # the help function
|
||||
|
||||
if ($opt_host eq '')
|
||||
{
|
||||
$sqlhost = "localhost";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sqlhost = $opt_host;
|
||||
}
|
||||
|
||||
# ask for a password if no password is set already
|
||||
if ($opt_password eq '')
|
||||
{
|
||||
system "stty -echo";
|
||||
print "Password for user $opt_user to connect to MySQL: ";
|
||||
$opt_password = <STDIN>;
|
||||
chomp($opt_password);
|
||||
system "stty echo";
|
||||
print "\n";
|
||||
}
|
||||
|
||||
|
||||
# make the connection to MySQL
|
||||
$dbh= DBI->connect("DBI:mysql:mysql:host=$sqlhost:port=$opt_port:mysql_socket=$opt_socket",$opt_user,$opt_password, {PrintError => 0}) ||
|
||||
die("Can't make a connection to the mysql server.\n The error: $DBI::errstr");
|
||||
|
||||
# the start of the program
|
||||
&q1();
|
||||
exit(0); # the end...
|
||||
|
||||
#####
|
||||
# below all subroutines of the program
|
||||
#####
|
||||
|
||||
###
|
||||
# the beginning of the program
|
||||
###
|
||||
sub q1 { # first question ...
|
||||
my ($answer,$end);
|
||||
while (! $end) {
|
||||
print "#"x70;
|
||||
print "\n";
|
||||
print "## Welcome to the permission setter $version for MySQL.\n";
|
||||
print "## made by Luuk de Boer\n";
|
||||
print "#"x70;
|
||||
print "\n";
|
||||
print "What would you like to do:\n";
|
||||
print " 1. Set password for an existing user.\n";
|
||||
print " 2. Create a database + user privilege for that database\n";
|
||||
print " and host combination (user can only do SELECT)\n";
|
||||
print " 3. Create/append user privilege for an existing database\n";
|
||||
print " and host combination (user can only do SELECT)\n";
|
||||
print " 4. Create/append broader user privileges for an existing\n";
|
||||
print " database and host combination\n";
|
||||
print " (user can do SELECT,INSERT,UPDATE,DELETE)\n";
|
||||
print " 5. Create/append quite extended user privileges for an\n";
|
||||
print " existing database and host combination (user can do\n";
|
||||
print " SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,\n";
|
||||
print " LOCK TABLES,CREATE TEMPORARY TABLES)\n";
|
||||
print " 6. Create/append full privileges for an existing database\n";
|
||||
print " and host combination (user has FULL privilege)\n";
|
||||
print " 7. Remove all privileges for for an existing database and\n";
|
||||
print " host combination.\n";
|
||||
print " (user will have all permission fields set to N)\n";
|
||||
print " 0. exit this program\n";
|
||||
print "\nMake your choice [1,2,3,4,5,6,7,0]: ";
|
||||
while (<STDIN>) {
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer =~ /^[1234567]$/) {
|
||||
if ($answer == 1) {
|
||||
setpwd();
|
||||
} elsif ($answer =~ /^[234567]$/) {
|
||||
addall($answer);
|
||||
} else {
|
||||
print "Sorry, something went wrong. With such option number you should not get here.\n\n";
|
||||
$end = 1;
|
||||
}
|
||||
} elsif ($answer == 0) {
|
||||
print "We hope we can help you next time \n\n";
|
||||
$end = 1;
|
||||
} else {
|
||||
print "Your answer was $answer\n";
|
||||
print "and that's wrong .... Try again\n";
|
||||
}
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
# set a password for a user
|
||||
###
|
||||
sub setpwd
|
||||
{
|
||||
my ($user,$pass,$host) = "";
|
||||
print "\n\nSetting a (new) password for a user.\n";
|
||||
|
||||
$user = user();
|
||||
$pass = newpass($user);
|
||||
$host = hosts($user);
|
||||
|
||||
print "#"x70;
|
||||
print "\n\n";
|
||||
print "That was it ... here is an overview of what you gave to me:\n";
|
||||
print "The username : $user\n";
|
||||
# print "The password : $pass\n";
|
||||
print "The host : $host\n";
|
||||
print "#"x70;
|
||||
print "\n\n";
|
||||
print "Are you pretty sure you would like to implement this [yes/no]: ";
|
||||
my $no = <STDIN>;
|
||||
chomp($no);
|
||||
if ($no =~ /n/i)
|
||||
{
|
||||
print "Okay .. that was it then ... See ya\n\n";
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Okay ... let's go then ...\n\n";
|
||||
}
|
||||
$user = $dbh->quote($user);
|
||||
$host = $dbh->quote($host);
|
||||
if ($pass eq '')
|
||||
{
|
||||
$pass = "''";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pass = "PASSWORD(". $dbh->quote($pass) . ")";
|
||||
}
|
||||
my $sth = $dbh->prepare("update user set Password=$pass where User = $user and Host = $host") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
$sth->finish;
|
||||
print "The password is set for user $user.\n\n";
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
# all things which will be added are done here
|
||||
###
|
||||
sub addall {
|
||||
my ($todo) = @_;
|
||||
my ($answer,$good,$db,$user,$pass,$host,$priv);
|
||||
|
||||
if ($todo == 2) {
|
||||
$db = newdatabase();
|
||||
} else {
|
||||
$db = database();
|
||||
}
|
||||
|
||||
$user = newuser();
|
||||
$pass = newpass("$user");
|
||||
$host = newhosts();
|
||||
|
||||
print "#"x70;
|
||||
print "\n\n";
|
||||
print "That was it ... here is an overview of what you gave to me:\n";
|
||||
print "The database name : $db\n";
|
||||
print "The username : $user\n";
|
||||
# print "The password : $pass\n";
|
||||
print "The host(s) : $host\n";
|
||||
print "#"x70;
|
||||
print "\n\n";
|
||||
print "Are you pretty sure you would like to implement this [yes/no]: ";
|
||||
my $no = <STDIN>;
|
||||
chomp($no);
|
||||
if ($no =~ /n/i) {
|
||||
print "Okay .. that was it then ... See ya\n\n";
|
||||
return(0);
|
||||
} else {
|
||||
print "Okay ... let's go then ...\n\n";
|
||||
}
|
||||
|
||||
if ($todo == 2) {
|
||||
# create the database
|
||||
if ($db) {
|
||||
my $sth = $dbh->do("CREATE DATABASE $db") || $dbh->errstr;
|
||||
} else {
|
||||
print STDERR "What do you want? You wanted to create new database and add new user, right?\n";
|
||||
die "But then specify databasename, please\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( !$todo ) or not ( $todo =~ m/^[2-7]$/ ) ) {
|
||||
print STDERR "Sorry, select option $todo isn't known inside the program .. See ya\n";
|
||||
quit();
|
||||
}
|
||||
|
||||
my @hosts = split(/,/,$host);
|
||||
if (!$user) {
|
||||
die "username not specified: $user\n";
|
||||
}
|
||||
if (!$db) {
|
||||
die "databasename is not specified nor *\n";
|
||||
}
|
||||
foreach $host (@hosts) {
|
||||
# user privileges: SELECT
|
||||
if (($todo == 2) || ($todo == 3)) {
|
||||
$sth = $dbh->do("GRANT SELECT ON $db.* TO \'$user\'@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr;
|
||||
} elsif ($todo == 4) {
|
||||
# user privileges: SELECT,INSERT,UPDATE,DELETE
|
||||
$sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE ON $db.* TO \'$user\'@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr;
|
||||
} elsif ($todo == 5) {
|
||||
# user privileges: SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES
|
||||
$sth = $dbh->do("GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,LOCK TABLES,CREATE TEMPORARY TABLES ON $db.* TO \'$user\'@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr;
|
||||
} elsif ($todo == 6) {
|
||||
# all privileges
|
||||
$sth = $dbh->do("GRANT ALL ON $db.* TO \'$user\'\@\'$host\' IDENTIFIED BY \'$pass\'") || die $dbh->errstr;
|
||||
} elsif ($todo == 7) {
|
||||
# all privileges set to N
|
||||
$sth = $dbh->do("REVOKE ALL ON $db.* FROM \'$user\'\@\'$host\'") || die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
$dbh->do("FLUSH PRIVILEGES") || print STDERR "Can't flush privileges\n";
|
||||
print "Everything is inserted and mysql privileges have been reloaded.\n\n";
|
||||
}
|
||||
|
||||
###
|
||||
# ask for a new database name
|
||||
###
|
||||
sub newdatabase {
|
||||
my ($answer,$good,$db);
|
||||
print "\n\nWhich database would you like to add: ";
|
||||
while (<STDIN>) {
|
||||
$answer = $_;
|
||||
$good = 0;
|
||||
chomp($answer);
|
||||
if ($answer) {
|
||||
my $sth = $dbh->prepare("SHOW DATABASES") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
while (my @r = $sth->fetchrow_array) {
|
||||
if ($r[0] eq $answer) {
|
||||
print "\n\nSorry, this database name is already in use; try something else: ";
|
||||
$good = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "You must type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last if ($good == 0);
|
||||
}
|
||||
$db = $answer;
|
||||
print "The new database $db will be created\n";
|
||||
return($db);
|
||||
}
|
||||
|
||||
###
|
||||
# select a database
|
||||
###
|
||||
sub database {
|
||||
my ($answer,$good,$db);
|
||||
print "\n\nWhich database from existing databases would you like to select: \n";
|
||||
print "You can choose from: \n";
|
||||
my $sth = $dbh->prepare("show databases") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
while (my @r = $sth->fetchrow_array) {
|
||||
print " - $r[0] \n";
|
||||
}
|
||||
print "Which database will it be (case sensitive). Type * for any: \n";
|
||||
while (<STDIN>) {
|
||||
$answer = $_;
|
||||
$good = 0;
|
||||
chomp($answer);
|
||||
if ($answer) {
|
||||
if ($answer eq "*") {
|
||||
print "OK, the user entry will NOT be limited to any database";
|
||||
return("*");
|
||||
}
|
||||
my $sth = $dbh->prepare("show databases") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
while (my @r = $sth->fetchrow_array) {
|
||||
if ($r[0] eq $answer) {
|
||||
$good = 1;
|
||||
$db = $r[0];
|
||||
last;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "Type either database name or * meaning any databasename. That means";
|
||||
print " any of those above but also any which will be created in future!";
|
||||
print " This option gives a user chance to operate on databse mysql, which";
|
||||
print " contains privilege settings. That is really risky!\n";
|
||||
next;
|
||||
}
|
||||
if ($good == 1) {
|
||||
last;
|
||||
} else {
|
||||
print "You must select one from the list.\nTry again: ";
|
||||
next;
|
||||
}
|
||||
}
|
||||
print "The database $db will be used.\n";
|
||||
return($db);
|
||||
}
|
||||
|
||||
###
|
||||
# ask for a new username
|
||||
###
|
||||
sub newuser
|
||||
{
|
||||
my $user = "";
|
||||
my $answer = "";
|
||||
|
||||
print "\nWhat username is to be created: ";
|
||||
while(<STDIN>)
|
||||
{
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer)
|
||||
{
|
||||
$user = $answer;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You must type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last;
|
||||
}
|
||||
print "Username = $user\n";
|
||||
return($user);
|
||||
}
|
||||
|
||||
###
|
||||
# ask for a user which is already in the user table
|
||||
###
|
||||
sub user
|
||||
{
|
||||
my ($answer,$user);
|
||||
|
||||
print "\nFor which user do you want to specify a password: ";
|
||||
while(<STDIN>)
|
||||
{
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer)
|
||||
{
|
||||
my $sth = $dbh->prepare("select User from user where User = '$answer'") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
my @r = $sth->fetchrow_array;
|
||||
if ($r[0])
|
||||
{
|
||||
$user = $r[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Sorry, user $answer isn't known in the user table.\nTry again: ";
|
||||
next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You must type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last;
|
||||
}
|
||||
print "Username = $user\n";
|
||||
return($user);
|
||||
}
|
||||
|
||||
###
|
||||
# ask for a new password
|
||||
###
|
||||
sub newpass
|
||||
{
|
||||
my ($user) = @_;
|
||||
my ($pass,$answer,$good,$yes);
|
||||
|
||||
print "Would you like to set a password for $user [y/n]: ";
|
||||
$yes = <STDIN>;
|
||||
chomp($yes);
|
||||
if ($yes =~ /y/)
|
||||
{
|
||||
system "stty -echo";
|
||||
print "What password do you want to specify for $user: ";
|
||||
while(<STDIN>)
|
||||
{
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
system "stty echo";
|
||||
print "\n";
|
||||
if ($answer)
|
||||
{
|
||||
system "stty -echo";
|
||||
print "Type the password again: ";
|
||||
my $second = <STDIN>;
|
||||
chomp($second);
|
||||
system "stty echo";
|
||||
print "\n";
|
||||
if ($answer ne $second)
|
||||
{
|
||||
print "Passwords aren't the same; we begin from scratch again.\n";
|
||||
system "stty -echo";
|
||||
print "Password please: ";
|
||||
next;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pass = $answer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You must type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last;
|
||||
}
|
||||
# print "The password for $user is $pass.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "We won't set a password so the user doesn't have to use it\n";
|
||||
$pass = "";
|
||||
}
|
||||
return($pass);
|
||||
}
|
||||
|
||||
###
|
||||
# ask for new hosts
|
||||
###
|
||||
sub newhosts
|
||||
{
|
||||
my ($host,$answer,$good);
|
||||
|
||||
print "We now need to know from what host(s) the user will connect.\n";
|
||||
print "Keep in mind that % means 'from any host' ...\n";
|
||||
print "The host please: ";
|
||||
while(<STDIN>)
|
||||
{
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer)
|
||||
{
|
||||
$host .= ",$answer";
|
||||
print "Would you like to add another host [yes/no]: ";
|
||||
my $yes = <STDIN>;
|
||||
chomp($yes);
|
||||
if ($yes =~ /y/i)
|
||||
{
|
||||
print "Okay, give us the host please: ";
|
||||
next;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Okay we keep it with this ...\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You must type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last;
|
||||
}
|
||||
$host =~ s/^,//;
|
||||
print "The following host(s) will be used: $host.\n";
|
||||
return($host);
|
||||
}
|
||||
|
||||
###
|
||||
# ask for a host which is already in the user table
|
||||
###
|
||||
sub hosts
|
||||
{
|
||||
my ($user) = @_;
|
||||
my ($answer,$good,$host);
|
||||
|
||||
print "We now need to know which host for $user we have to change.\n";
|
||||
print "Choose from the following hosts: \n";
|
||||
$user = $dbh->quote($user);
|
||||
my $sth = $dbh->prepare("select Host,User from user where User = $user") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
while (my @r = $sth->fetchrow_array)
|
||||
{
|
||||
print " - $r[0] \n";
|
||||
}
|
||||
print "The host please (case sensitive): ";
|
||||
while(<STDIN>)
|
||||
{
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer)
|
||||
{
|
||||
$sth = $dbh->prepare("select Host,User from user where Host = '$answer' and User = $user") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
my @r = $sth->fetchrow_array;
|
||||
if ($r[0])
|
||||
{
|
||||
$host = $answer;
|
||||
last;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You have to select a host from the list ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You have to type something ...\nTry again: ";
|
||||
next;
|
||||
}
|
||||
last;
|
||||
}
|
||||
print "The following host will be used: $host.\n";
|
||||
return($host);
|
||||
}
|
||||
|
||||
###
|
||||
# a nice quit (first disconnect and then exit
|
||||
###
|
||||
sub quit
|
||||
{
|
||||
$dbh->disconnect;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
###
|
||||
# Read variables password, port and socket from .my.cnf under the client
|
||||
# or perl groups
|
||||
###
|
||||
|
||||
sub read_my_cnf
|
||||
{
|
||||
open(TMP,$ENV{'HOME'} . "/.my.cnf") || return 1;
|
||||
while (<TMP>)
|
||||
{
|
||||
if (/^\[(client|perl)\]/i)
|
||||
{
|
||||
while ((defined($_=<TMP>)) && !/^\[\w+\]/)
|
||||
{
|
||||
print $_;
|
||||
if (/^host\s*=\s*(\S+)/i)
|
||||
{
|
||||
$opt_host = $1;
|
||||
}
|
||||
elsif (/^user\s*=\s*(\S+)/i)
|
||||
{
|
||||
$opt_user = $1;
|
||||
}
|
||||
elsif (/^password\s*=\s*(\S+)/i)
|
||||
{
|
||||
$opt_password = $1;
|
||||
}
|
||||
elsif (/^port\s*=\s*(\S+)/i)
|
||||
{
|
||||
$opt_port = $1;
|
||||
}
|
||||
elsif (/^socket\s*=\s*(\S+)/i)
|
||||
{
|
||||
$opt_socket = $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(TMP);
|
||||
}
|
||||
|
||||
###
|
||||
# the help text
|
||||
###
|
||||
sub usage
|
||||
{
|
||||
print <<EOL;
|
||||
----------------------------------------------------------------------
|
||||
The permission setter for MySQL.
|
||||
version: $version
|
||||
|
||||
made by: Luuk de Boer <luuk\@wxs.nl>
|
||||
----------------------------------------------------------------------
|
||||
|
||||
The permission setter is a little program which can help you add users
|
||||
or databases or change passwords in MySQL. Keep in mind that we don't
|
||||
check permissions which already been set in MySQL. So if you can't
|
||||
connect to MySQL using the permission you just added, take a look at
|
||||
the permissions which have already been set in MySQL.
|
||||
|
||||
The permission setter first reads your .my.cnf file in your Home
|
||||
directory if it exists.
|
||||
|
||||
Options for the permission setter:
|
||||
|
||||
--help : print this help message and exit.
|
||||
|
||||
The options shown below are used for making the connection to the MySQL
|
||||
server. Keep in mind that the permissions for the user specified via
|
||||
these options must be sufficient to add users / create databases / set
|
||||
passwords.
|
||||
|
||||
--user : is the username to connect with.
|
||||
--password : the password of the username.
|
||||
--host : the host to connect to.
|
||||
--socket : the socket to connect to.
|
||||
--port : the port number of the host to connect to.
|
||||
|
||||
If you don't give a password and no password is set in your .my.cnf
|
||||
file, then the permission setter will ask for a password.
|
||||
|
||||
|
||||
EOL
|
||||
exit(0);
|
||||
}
|
||||
BIN
database/bin/mysql_tzinfo_to_sql
Executable file
BIN
database/bin/mysql_tzinfo_to_sql
Executable file
Binary file not shown.
BIN
database/bin/mysql_upgrade
Executable file
BIN
database/bin/mysql_upgrade
Executable file
Binary file not shown.
BIN
database/bin/mysql_waitpid
Executable file
BIN
database/bin/mysql_waitpid
Executable file
Binary file not shown.
171
database/bin/mysql_zap
Executable file
171
database/bin/mysql_zap
Executable file
|
|
@ -0,0 +1,171 @@
|
|||
#!/usr/bin/perl
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
# This is a utility for MySQL. It is not needed by any standard part
|
||||
# of MySQL.
|
||||
|
||||
# Usage: mysql_zap [-signal] [-f] [-t] pattern
|
||||
|
||||
# Configuration parameters.
|
||||
|
||||
$sig = ""; # Default to try all signals
|
||||
$ans = "y";
|
||||
$opt_f= 0;
|
||||
$opt_t= 0;
|
||||
$opt_a = "";
|
||||
|
||||
$BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4";
|
||||
$LINUX = $^O eq 'linux' || $^O eq 'darwin';
|
||||
$pscmd = $BSD ? "/bin/ps -auxww" : $LINUX ? "/bin/ps axuw" : "/bin/ps -ef";
|
||||
|
||||
open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!";
|
||||
open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!";
|
||||
select(TTYOUT);
|
||||
$| = 1;
|
||||
select(STDOUT);
|
||||
$SIG{'INT'} = 'cleanup';
|
||||
|
||||
while ($#ARGV >= $[ && $ARGV[0] =~ /^-/) {
|
||||
if ($ARGV[0] =~ /(ZERO|HUP|INT|QUIT|ILL|TRAP|ABRT|EMT|FPE|KILL|BUS|SEGV|SYS|PIPE|ALRM|TERM|URG|STOP|TSTP|CONT|CLD|TTIN|TTOU|IO|XCPU|XFSZ|VTALRM|PROF|WINCH|LOST|USR1|USR2)/ || $ARGV[0] =~ /-(\d+)$/) {
|
||||
$sig = $1;
|
||||
} elsif ($ARGV[0] eq "-f") {
|
||||
$opt_f=1;
|
||||
} elsif ($ARGV[0] eq "-t") {
|
||||
$opt_t=1;
|
||||
$ans = "n";
|
||||
}
|
||||
elsif ($ARGV[0] eq "-a")
|
||||
{
|
||||
$opt_a = 1;
|
||||
}
|
||||
elsif ($ARGV[0] eq "-?" || $ARGV[0] eq "-I" || $ARGV[0] eq "--help")
|
||||
{
|
||||
&usage;
|
||||
}
|
||||
else {
|
||||
print STDERR "$0: illegal argument $ARGV[0] ignored\n";
|
||||
}
|
||||
shift;
|
||||
}
|
||||
|
||||
&usage if $#ARGV < 0;
|
||||
|
||||
if (!$opt_f)
|
||||
{
|
||||
if ($BSD) {
|
||||
system "stty cbreak </dev/tty >/dev/tty 2>&1";
|
||||
}
|
||||
else {
|
||||
system "stty", 'cbreak',
|
||||
system "stty", 'eol', '^A';
|
||||
}
|
||||
}
|
||||
|
||||
open(PS, "$pscmd|") || die "can't run $pscmd: $!";
|
||||
$title = <PS>;
|
||||
print TTYOUT $title;
|
||||
|
||||
# Catch any errors with eval. A bad pattern, for instance.
|
||||
eval <<'EOF';
|
||||
process: while ($cand = <PS>)
|
||||
{
|
||||
chop($cand);
|
||||
($user, $pid) = split(' ', $cand);
|
||||
next if $pid == $$;
|
||||
$found = !@ARGV;
|
||||
if ($opt_a) { $found = 1; }
|
||||
foreach $pat (@ARGV)
|
||||
{
|
||||
if ($opt_a)
|
||||
{
|
||||
if (! ($cand =~ $pat))
|
||||
{
|
||||
next process;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$found = 1 if $cand =~ $pat;
|
||||
}
|
||||
}
|
||||
next if (!$found);
|
||||
if (! $opt_f && ! $opt_t)
|
||||
{
|
||||
print TTYOUT "$cand? ";
|
||||
read(TTYIN, $ans, 1);
|
||||
print TTYOUT "\n" if ($ans ne "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
print TTYOUT "$cand\n";
|
||||
}
|
||||
if ($ans =~ /^y/i) { &killpid($sig, $pid); }
|
||||
if ($ans =~ /^q/i) { last; }
|
||||
}
|
||||
EOF
|
||||
|
||||
&cleanup;
|
||||
|
||||
|
||||
sub usage {
|
||||
print <<EOF;
|
||||
Usage: $0 [-signal] [-?Ift] [--help] pattern
|
||||
Options: -I or -? "info" -f "force" -t "test".
|
||||
|
||||
Version 1.0
|
||||
Kill processes that match the pattern.
|
||||
If -f isn't given, ask user for confirmation for each process to kill.
|
||||
If signal isn't given, try first with signal 15, then with signal 9.
|
||||
If -t is given, the processes are only shown on stdout.
|
||||
EOF
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub cleanup {
|
||||
if ($BSD) {
|
||||
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
|
||||
}
|
||||
else {
|
||||
system "stty", 'icanon';
|
||||
system "stty", 'eol', '^@';
|
||||
}
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
sub killpid {
|
||||
local($signal,$pid) = @_;
|
||||
if ($signal)
|
||||
{
|
||||
kill $signal,$pid;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "kill -15\n";
|
||||
kill 15, $pid;
|
||||
for (1..5) {
|
||||
sleep 2;
|
||||
return if kill(0, $pid) == 0;
|
||||
}
|
||||
print "kill -9\n";
|
||||
kill 9, $pid;
|
||||
for (1..5) {
|
||||
sleep 2;
|
||||
return if kill(0, $pid) == 0;
|
||||
}
|
||||
print "$pid will not die!\n";
|
||||
}
|
||||
}
|
||||
3265
database/bin/mysqlaccess
Executable file
3265
database/bin/mysqlaccess
Executable file
File diff suppressed because it is too large
Load diff
BIN
database/bin/mysqladmin
Executable file
BIN
database/bin/mysqladmin
Executable file
Binary file not shown.
BIN
database/bin/mysqlbinlog
Executable file
BIN
database/bin/mysqlbinlog
Executable file
Binary file not shown.
408
database/bin/mysqlbug
Executable file
408
database/bin/mysqlbug
Executable file
|
|
@ -0,0 +1,408 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2000-2002, 2004 MySQL AB
|
||||
# Use is subject to license terms
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
|
||||
# Create a bug report and mail it to the mysql mailing list
|
||||
# Based on glibc bug reporting script.
|
||||
|
||||
echo "Finding system information for a MySQL bug report"
|
||||
|
||||
VERSION="5.5.68"
|
||||
COMPILATION_COMMENT="MariaDB Server"
|
||||
BUGmysql="maria-developers@lists.launchpad.net"
|
||||
# This is set by configure
|
||||
COMP_CALL_INFO="CC='/usr/local/bin/cc' CFLAGS='' CXX='/usr/local/bin/c++' CXXFLAGS='' LDFLAGS='' ASFLAGS=''"
|
||||
COMP_RUN_INFO="CC='/usr/local/bin/cc' CFLAGS='' CXX='/usr/local/bin/c++' CXXFLAGS='' LDFLAGS='' ASFLAGS=''"
|
||||
CONFIGURE_LINE=""
|
||||
|
||||
LIBC_INFO=""
|
||||
for pat in /lib/libc.* /lib/libc-* /usr/lib/libc.* /usr/lib/libc-*
|
||||
do
|
||||
TMP=`ls -l $pat 2>/dev/null`
|
||||
if test $? = 0
|
||||
then
|
||||
LIBC_INFO="$LIBC_INFO
|
||||
$TMP"
|
||||
fi
|
||||
done
|
||||
|
||||
PATH=../client:$PATH:/bin:/usr/bin:/usr/local/bin
|
||||
export PATH
|
||||
|
||||
BUGADDR=${1-$BUGmysql}
|
||||
ENVIRONMENT=`uname -a`
|
||||
|
||||
: ${USER=${LOGNAME-`whoami`}}
|
||||
|
||||
COMMAND=`echo $0|sed 's%.*/\([^/]*\)%\1%'`
|
||||
|
||||
# Try to create a secure tmpfile
|
||||
umask 077
|
||||
TEMPDIR=/tmp/mysqlbug-$$
|
||||
mkdir $TEMPDIR || (echo "can not create directory in /tmp, aborting"; exit 1;)
|
||||
TEMP=${TEMPDIR}/mysqlbug
|
||||
|
||||
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR; exit 1' 1 2 3 13 15
|
||||
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR' 0
|
||||
|
||||
# How to read the passwd database.
|
||||
PASSWD="cat /etc/passwd"
|
||||
|
||||
if test -f /usr/lib/sendmail
|
||||
then
|
||||
MAIL_AGENT="/usr/lib/sendmail -oi -t"
|
||||
elif test -f /usr/sbin/sendmail
|
||||
then
|
||||
MAIL_AGENT="/usr/sbin/sendmail -oi -t"
|
||||
else
|
||||
MAIL_AGENT="rmail $BUGmysql"
|
||||
fi
|
||||
|
||||
# Figure out how to echo a string without a trailing newline
|
||||
N=`echo 'hi there\c'`
|
||||
case "$N" in
|
||||
*c) ECHON1='echo -n' ECHON2= ;;
|
||||
*) ECHON1=echo ECHON2='\c' ;;
|
||||
esac
|
||||
|
||||
# Find out the name of the originator of this PR.
|
||||
if test -n "$NAME"
|
||||
then
|
||||
ORIGINATOR="$NAME"
|
||||
elif test -f $HOME/.fullname
|
||||
then
|
||||
ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
|
||||
else
|
||||
# Must use temp file due to incompatibilities in quoting behavior
|
||||
# and to protect shell metacharacters in the expansion of $LOGNAME
|
||||
$PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
|
||||
ORIGINATOR="`cat $TEMP`"
|
||||
rm -f $TEMP
|
||||
fi
|
||||
|
||||
if test -n "$ORGANIZATION"
|
||||
then
|
||||
if test -f "$ORGANIZATION"
|
||||
then
|
||||
ORGANIZATION="`cat $ORGANIZATION`"
|
||||
fi
|
||||
else
|
||||
if test -f $HOME/.organization
|
||||
then
|
||||
ORGANIZATION="`cat $HOME/.organization`"
|
||||
elif test -f $HOME/.signature
|
||||
then
|
||||
ORGANIZATION=`sed -e "s/^/ /" $HOME/.signature; echo ">"`
|
||||
fi
|
||||
fi
|
||||
|
||||
PATH_DIRS=`echo $PATH | sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `
|
||||
|
||||
which_1 ()
|
||||
{
|
||||
for cmd
|
||||
do
|
||||
# Absolute path ?.
|
||||
if expr "x$cmd" : "x/" > /dev/null
|
||||
then
|
||||
echo "$cmd"
|
||||
exit 0
|
||||
else
|
||||
for d in $PATH_DIRS
|
||||
do
|
||||
file="$d/$cmd"
|
||||
if test -x "$file" -a ! -d "$file"
|
||||
then
|
||||
echo "$file"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
exit 1
|
||||
}
|
||||
|
||||
change_editor ()
|
||||
{
|
||||
echo "You can change editor by setting the environment variable VISUAL."
|
||||
echo "If your shell is a bourne shell (sh) do"
|
||||
echo "VISUAL=your_editors_name; export VISUAL"
|
||||
echo "If your shell is a C shell (csh) do"
|
||||
echo "setenv VISUAL your_editors_name"
|
||||
}
|
||||
|
||||
# If they don't have a preferred editor set, then use emacs
|
||||
if test -z "$VISUAL"
|
||||
then
|
||||
if test -z "$EDITOR"
|
||||
then
|
||||
# Honor debian sensible-editor
|
||||
if test -x "/usr/bin/sensible-editor"
|
||||
then
|
||||
EDIT=/usr/bin/sensible-editor
|
||||
else
|
||||
EDIT=emacs
|
||||
fi
|
||||
else
|
||||
EDIT="$EDITOR"
|
||||
fi
|
||||
else
|
||||
EDIT="$VISUAL"
|
||||
fi
|
||||
|
||||
#which_1 $EDIT
|
||||
used_editor=`which_1 $EDIT`
|
||||
|
||||
echo "test -x $used_editor"
|
||||
if test -x "$used_editor"
|
||||
then
|
||||
echo "Using editor $used_editor";
|
||||
change_editor
|
||||
sleep 2
|
||||
else
|
||||
echo "Could not find a text editor. (tried $EDIT)"
|
||||
change_editor
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find out some information.
|
||||
SYSTEM=`( test -f /bin/uname && /bin/uname -a ) || \
|
||||
( test -f /usr/bin/uname && /usr/bin/uname -a ) || echo ""`
|
||||
ARCH=`test -f /bin/arch && /bin/arch`
|
||||
MACHINE=`test -f /bin/machine && /bin/machine`
|
||||
FILE_PATHS=
|
||||
|
||||
for cmd in perl make gmake gcc cc
|
||||
do
|
||||
file=`which_1 $cmd`
|
||||
if test $? = 0
|
||||
then
|
||||
if test $cmd = "gcc"
|
||||
then
|
||||
GCC_INFO=`$file -v 2>&1`
|
||||
elif test $cmd = "perl"
|
||||
then
|
||||
PERL_INFO=`$file -v | grep -i version 2>&1`
|
||||
fi
|
||||
FILE_PATHS="$FILE_PATHS $file"
|
||||
fi
|
||||
done
|
||||
|
||||
admin=`which_1 mysqladmin`
|
||||
MYSQL_SERVER=
|
||||
if test -x "$admin"
|
||||
then
|
||||
MYSQL_SERVER=`$admin version 2> /dev/null`
|
||||
if test "$?" = "1"
|
||||
then
|
||||
MYSQL_SERVER=""
|
||||
fi
|
||||
fi
|
||||
|
||||
SUBJECT_C="[50 character or so descriptive subject here (for reference)]"
|
||||
ORGANIZATION_C='<organization of PR author (multiple lines)>'
|
||||
LICENCE_C='[none | licence | email support | extended email support ]'
|
||||
SYNOPSIS_C='<synopsis of the problem (one line)>'
|
||||
SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
|
||||
PRIORITY_C='<[ low | medium | high ] (one line)>'
|
||||
CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
|
||||
RELEASE_C='<release number or tag (one line)>'
|
||||
ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
|
||||
DESCRIPTION_C='<precise description of the problem (multiple lines)>'
|
||||
HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
|
||||
FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
|
||||
|
||||
|
||||
cat > $TEMP <<EOF
|
||||
SEND-PR: -*- send-pr -*-
|
||||
SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
|
||||
SEND-PR: will all comments (text enclosed in \`<' and \`>').
|
||||
SEND-PR:
|
||||
From: ${USER}
|
||||
To: ${BUGADDR}
|
||||
Subject: $SUBJECT_C
|
||||
|
||||
>Description:
|
||||
$DESCRIPTION_C
|
||||
>How-To-Repeat:
|
||||
$HOW_TO_REPEAT_C
|
||||
>Fix:
|
||||
$FIX_C
|
||||
|
||||
>Submitter-Id: <submitter ID>
|
||||
>Originator: ${ORIGINATOR}
|
||||
>Organization:
|
||||
${ORGANIZATION- $ORGANIZATION_C}
|
||||
>MySQL support: $LICENCE_C
|
||||
>Synopsis: $SYNOPSIS_C
|
||||
>Severity: $SEVERITY_C
|
||||
>Priority: $PRIORITY_C
|
||||
>Category: mysql
|
||||
>Class: $CLASS_C
|
||||
>Release: mysql-${VERSION} ($COMPILATION_COMMENT)
|
||||
`test -n "$MYSQL_SERVER" && echo ">Server: $MYSQL_SERVER"`
|
||||
>C compiler: cc (GCC) 4.8.5
|
||||
|
||||
>C++ compiler: c++ (GCC) 4.8.5
|
||||
|
||||
>Environment:
|
||||
$ENVIRONMENT_C
|
||||
`test -n "$SYSTEM" && echo "System: $SYSTEM"`
|
||||
`test -n "$ARCH" && echo "Architecture: $ARCH"`
|
||||
`test -n "$MACHINE" && echo "Machine: $MACHINE"`
|
||||
`test -n "$FILE_PATHS" && echo "Some paths: $FILE_PATHS"`
|
||||
`test -n "$GCC_INFO" && echo "GCC: $GCC_INFO"`
|
||||
`test -n "$COMP_CALL_INFO" && echo "Compilation info (call): $COMP_CALL_INFO"`
|
||||
`test -n "$COMP_RUN_INFO" && echo "Compilation info (used): $COMP_RUN_INFO"`
|
||||
`test -n "$LIBC_INFO" && echo "LIBC: $LIBC_INFO"`
|
||||
`test -n "$CONFIGURE_LINE" && echo "Configure command: $CONFIGURE_LINE"`
|
||||
`test -n "$PERL_INFO" && echo "Perl: $PERL_INFO"`
|
||||
EOF
|
||||
|
||||
chmod u+w $TEMP
|
||||
cp $TEMP $TEMP.x
|
||||
|
||||
eval $EDIT $TEMP
|
||||
|
||||
if cmp -s $TEMP $TEMP.x
|
||||
then
|
||||
echo "File not changed, no bug report submitted."
|
||||
mv -f $TEMP /tmp/failed-mysql-bugreport
|
||||
echo "The raw bug report exists in /tmp/failed-mysql-bugreport"
|
||||
echo "If you use this remember that the first lines of the report are now a lie.."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Check the enumeration fields
|
||||
|
||||
# This is a "sed-subroutine" with one keyword parameter
|
||||
# (with workaround for Sun sed bug)
|
||||
#
|
||||
SED_CMD='
|
||||
/$PATTERN/{
|
||||
s|||
|
||||
s|<.*>||
|
||||
s|^[ ]*||
|
||||
s|[ ]*$||
|
||||
p
|
||||
q
|
||||
}'
|
||||
|
||||
|
||||
while :; do
|
||||
CNT=0
|
||||
|
||||
#
|
||||
# 1) Severity
|
||||
#
|
||||
PATTERN=">Severity:"
|
||||
SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
|
||||
case "$SEVERITY" in
|
||||
""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
|
||||
*) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
|
||||
esac
|
||||
#
|
||||
# 2) Priority
|
||||
#
|
||||
PATTERN=">Priority:"
|
||||
PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
|
||||
case "$PRIORITY" in
|
||||
""|low|medium|high) CNT=`expr $CNT + 1` ;;
|
||||
*) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
|
||||
esac
|
||||
#
|
||||
# 3) Class
|
||||
#
|
||||
PATTERN=">Class:"
|
||||
CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
|
||||
case "$CLASS" in
|
||||
""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
|
||||
*) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
|
||||
esac
|
||||
|
||||
#
|
||||
# 4) Synopsis
|
||||
#
|
||||
VALUE=`grep "^>Synopsis:" $TEMP | sed 's/>Synopsis:[ ]*//'`
|
||||
case "$VALUE" in
|
||||
"$SYNOPSIS_C") echo "$COMMAND: \`$VALUE' is not a valid value for \`Synopsis'." ;;
|
||||
*) CNT=`expr $CNT + 1`
|
||||
esac
|
||||
|
||||
test $CNT -lt 4 &&
|
||||
echo "Errors were found with the problem report."
|
||||
|
||||
|
||||
# Check if subject of mail was changed, if not, use Synopsis field
|
||||
#
|
||||
subject=`grep "^Subject" $TEMP| sed 's/^Subject:[ ]*//'`
|
||||
if [ X"$subject" = X"$SUBJECT_C" -o X"$subject" = X"$SYNOPSIS_C" ]; then
|
||||
subject=`grep Synopsis $TEMP | sed 's/>Synopsis:[ ]*//'`
|
||||
sed "s/^Subject:[ ]*.*/Subject: $subject/" $TEMP > $TEMP.tmp
|
||||
mv -f $TEMP.tmp $TEMP
|
||||
fi
|
||||
|
||||
while :; do
|
||||
$ECHON1 "a)bort, e)dit or s)end? $ECHON2"
|
||||
read input
|
||||
case "$input" in
|
||||
a*)
|
||||
echo "$COMMAND: problem report saved in $HOME/dead.mysqlbug."
|
||||
cat $TEMP >> $HOME/dead.mysqlbug
|
||||
xs=1; exit
|
||||
;;
|
||||
e*)
|
||||
eval $EDIT $TEMP
|
||||
continue 2
|
||||
;;
|
||||
s*)
|
||||
break 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
#
|
||||
# Remove comments and send the problem report
|
||||
# (we have to use patterns, where the comment contains regex chars)
|
||||
#
|
||||
# /^>Originator:/s;$ORIGINATOR;;
|
||||
sed -e "
|
||||
/^SEND-PR:/d
|
||||
/^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
|
||||
/^>Confidential:/s;<.*>;;
|
||||
/^>Synopsis:/s;$SYNOPSIS_C;;
|
||||
/^>Severity:/s;<.*>;;
|
||||
/^>Priority:/s;<.*>;;
|
||||
/^>Class:/s;<.*>;;
|
||||
/^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
|
||||
/^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
|
||||
/^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
|
||||
/^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
|
||||
/^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
|
||||
" $TEMP > $TEMP.x
|
||||
|
||||
if $MAIL_AGENT < $TEMP.x
|
||||
then
|
||||
echo "$COMMAND: problem report sent"
|
||||
xs=0; exit
|
||||
else
|
||||
echo "$COMMAND: mysterious mail failure, report not sent."
|
||||
echo "$COMMAND: problem report saved in $HOME/dead.mysqlbug."
|
||||
cat $TEMP >> $HOME/dead.mysqlbug
|
||||
fi
|
||||
|
||||
exit 0
|
||||
BIN
database/bin/mysqlcheck
Executable file
BIN
database/bin/mysqlcheck
Executable file
Binary file not shown.
BIN
database/bin/mysqld
Executable file
BIN
database/bin/mysqld
Executable file
Binary file not shown.
837
database/bin/mysqld_multi
Executable file
837
database/bin/mysqld_multi
Executable file
|
|
@ -0,0 +1,837 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates.
|
||||
# Copyright (c) 2010, 2017, MariaDB Corporation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; version 2
|
||||
# of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1335 USA
|
||||
|
||||
use Getopt::Long;
|
||||
use POSIX qw(strftime getcwd);
|
||||
|
||||
$|=1;
|
||||
$VER="2.16";
|
||||
|
||||
my @defaults_options; # Leading --no-defaults, --defaults-file, etc.
|
||||
|
||||
$opt_example = 0;
|
||||
$opt_help = 0;
|
||||
$opt_log = undef();
|
||||
$opt_mysqladmin = "/usr/local/mysql/bin/mysqladmin";
|
||||
$opt_mysqld = "./bin/mysqld";
|
||||
$opt_no_log = 0;
|
||||
$opt_password = undef();
|
||||
$opt_tcp_ip = 0;
|
||||
$opt_user = "root";
|
||||
$opt_version = 0;
|
||||
$opt_silent = 0;
|
||||
$opt_verbose = 0;
|
||||
|
||||
my $my_print_defaults_exists= 1;
|
||||
my $logdir= undef();
|
||||
|
||||
my ($mysqld, $mysqladmin, $groupids, $homedir, $my_progname);
|
||||
|
||||
$homedir = $ENV{HOME};
|
||||
$my_progname = $0;
|
||||
$my_progname =~ s/.*[\/]//;
|
||||
|
||||
|
||||
if (defined($ENV{UMASK})) {
|
||||
my $UMASK = $ENV{UMASK};
|
||||
my $m;
|
||||
my $fmode = "0640";
|
||||
|
||||
if(($UMASK =~ m/[^0246]/) || ($UMASK =~ m/^[^0]/) || (length($UMASK) != 4)) {
|
||||
printf("UMASK must be a 3-digit mode with an additional leading 0 to indicate octal.\n");
|
||||
printf("The first digit will be corrected to 6, the others may be 0, 2, 4, or 6.\n"); }
|
||||
else {
|
||||
$fmode= substr $UMASK, 2, 2;
|
||||
$fmode= "06${fmode}"; }
|
||||
|
||||
if($fmode != $UMASK) {
|
||||
printf("UMASK corrected from $UMASK to $fmode ...\n"); }
|
||||
|
||||
$fmode= oct($fmode);
|
||||
|
||||
umask($fmode);
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
|
||||
####
|
||||
#### main sub routine
|
||||
####
|
||||
|
||||
sub main
|
||||
{
|
||||
my $flag_exit= 0;
|
||||
|
||||
if (!defined(my_which(my_print_defaults)))
|
||||
{
|
||||
# We can't throw out yet, since --version, --help, or --example may
|
||||
# have been given
|
||||
print "WARNING: my_print_defaults command not found.\n";
|
||||
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";
|
||||
$my_print_defaults_exists= 0;
|
||||
}
|
||||
|
||||
# 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);
|
||||
}
|
||||
|
||||
foreach (@defaults_options)
|
||||
{
|
||||
$_ = quote_shell_word($_);
|
||||
}
|
||||
|
||||
# Add [mysqld_multi] options to front of @ARGV, ready for GetOptions()
|
||||
unshift @ARGV, defaults_for_group('mysqld_multi');
|
||||
|
||||
# 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"))
|
||||
{
|
||||
$flag_exit= 1;
|
||||
}
|
||||
usage() if ($opt_help);
|
||||
|
||||
if ($opt_verbose && $opt_silent)
|
||||
{
|
||||
print "Both --verbose and --silent have been given. Some of the warnings ";
|
||||
print "will be disabled\nand some will be enabled.\n\n";
|
||||
}
|
||||
|
||||
$groupids = $ARGV[1];
|
||||
if ($opt_version)
|
||||
{
|
||||
print "$my_progname version $VER by Jani Tolonen\n";
|
||||
exit(0);
|
||||
}
|
||||
example() if ($opt_example);
|
||||
if ($flag_exit)
|
||||
{
|
||||
print "Error with an option, see $my_progname --help for more info.\n";
|
||||
exit(1);
|
||||
}
|
||||
if (!defined(my_which(my_print_defaults)))
|
||||
{
|
||||
print "ABORT: Can't find command 'my_print_defaults'.\n";
|
||||
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);
|
||||
}
|
||||
usage() if (!defined($ARGV[0]) ||
|
||||
(!($ARGV[0] =~ m/^start$/i) &&
|
||||
!($ARGV[0] =~ m/^stop$/i) &&
|
||||
!($ARGV[0] =~ m/^report$/i)));
|
||||
|
||||
init_log() if (!defined($opt_log));
|
||||
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";
|
||||
}
|
||||
if ($ARGV[0] =~ m/^start$/i)
|
||||
{
|
||||
if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
|
||||
{
|
||||
print "WARNING: Couldn't find the default mysqld binary.\n";
|
||||
print "Tried: $opt_mysqld\n";
|
||||
print "This is OK, if you are using option \"mysqld=...\" in ";
|
||||
print "groups [mysqldN] separately for each.\n\n";
|
||||
}
|
||||
start_mysqlds();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Quote word for shell
|
||||
#
|
||||
|
||||
sub quote_shell_word
|
||||
{
|
||||
my ($option)= @_;
|
||||
|
||||
$option =~ s!([^\w=./-])!\\$1!g;
|
||||
return $option;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
####
|
||||
#### Init log file. Check for appropriate place for log file, in the following
|
||||
#### order: my_print_defaults mysqld datadir, /usr/local/mysql/share
|
||||
####
|
||||
|
||||
sub init_log
|
||||
{
|
||||
foreach my $opt (defaults_for_group('--mysqld'))
|
||||
{
|
||||
if ($opt =~ m/^--datadir=(.*)/ && -d "$1" && -w "$1")
|
||||
{
|
||||
$logdir= $1;
|
||||
}
|
||||
}
|
||||
if (!defined($logdir))
|
||||
{
|
||||
$logdir= "/usr/local/mysql/share" if (-d "/usr/local/mysql/share" && -w "/usr/local/mysql/share");
|
||||
}
|
||||
if (!defined($logdir))
|
||||
{
|
||||
# Log file was not specified and we could not log to a standard place,
|
||||
# so log file be disabled for now.
|
||||
if (!$opt_silent)
|
||||
{
|
||||
print "WARNING: Log file disabled. Maybe directory or file isn't writable?\n";
|
||||
}
|
||||
$opt_no_log= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt_log= "$logdir/mysqld_multi.log";
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### Report living and not running MySQL servers
|
||||
####
|
||||
|
||||
sub report_mysqlds
|
||||
{
|
||||
my (@groups, $com, $i, @options, $pec);
|
||||
|
||||
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++)
|
||||
{
|
||||
$com= get_mysqladmin_options($i, @groups);
|
||||
$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()
|
||||
{
|
||||
my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent);
|
||||
|
||||
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++)
|
||||
{
|
||||
@options = defaults_for_group($groups[$i]);
|
||||
|
||||
$basedir_found= 0; # The default
|
||||
$mysqld_found= 1; # The default
|
||||
$mysqld_found= 0 if (!length($mysqld));
|
||||
$com= "$mysqld";
|
||||
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
|
||||
{
|
||||
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||
{
|
||||
# catch this and ignore
|
||||
}
|
||||
elsif ("--mysqld=" eq substr($options[$j], 0, 9))
|
||||
{
|
||||
$options[$j]=~ s/\-\-mysqld\=//;
|
||||
$com= $options[$j];
|
||||
$mysqld_found= 1;
|
||||
}
|
||||
elsif ("--basedir=" eq substr($options[$j], 0, 10))
|
||||
{
|
||||
$basedir= $options[$j];
|
||||
$basedir =~ s/^--basedir=//;
|
||||
$basedir_found= 1;
|
||||
$options[$j]= quote_shell_word($options[$j]);
|
||||
$tmp.= " $options[$j]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$options[$j]= quote_shell_word($options[$j]);
|
||||
$tmp.= " $options[$j]";
|
||||
}
|
||||
}
|
||||
if ($opt_verbose && $com =~ m/\/(safe_mysqld|mysqld_safe)$/ && !$info_sent)
|
||||
{
|
||||
print "WARNING: $1 is being used to start mysqld. In this case you ";
|
||||
print "may need to pass\n\"ledir=...\" under groups [mysqldN] to ";
|
||||
print "$1 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;
|
||||
}
|
||||
$com.= $tmp;
|
||||
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
||||
$com.= " &";
|
||||
if (!$mysqld_found)
|
||||
{
|
||||
print "\n";
|
||||
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
|
||||
print "but no mysqld binary was found.\n";
|
||||
print "Please add \"mysqld=...\" in group [mysqld_multi], or add it to ";
|
||||
print "group [$groups[$i]] separately.\n";
|
||||
exit(1);
|
||||
}
|
||||
if ($basedir_found)
|
||||
{
|
||||
$curdir=getcwd();
|
||||
chdir($basedir) or die "Can't change to datadir $basedir";
|
||||
}
|
||||
system($com);
|
||||
if ($basedir_found)
|
||||
{
|
||||
chdir($curdir) or die "Can't change back to original dir $curdir";
|
||||
}
|
||||
}
|
||||
if (!$i && !$opt_no_log)
|
||||
{
|
||||
w2log("No MySQL servers to be started (check your GNRs)",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### stop multiple servers
|
||||
####
|
||||
|
||||
sub stop_mysqlds()
|
||||
{
|
||||
my (@groups, $com, $i, @options);
|
||||
|
||||
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++)
|
||||
{
|
||||
$com= get_mysqladmin_options($i, @groups);
|
||||
$com.= " shutdown";
|
||||
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
||||
$com.= " &";
|
||||
system($com);
|
||||
}
|
||||
if (!$i && !$opt_no_log)
|
||||
{
|
||||
w2log("No MySQL servers to be stopped (check your GNRs)",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### Sub function for mysqladmin option parsing
|
||||
####
|
||||
|
||||
sub get_mysqladmin_options
|
||||
{
|
||||
my ($i, @groups)= @_;
|
||||
my ($mysqladmin_found, $com, $tmp, $j);
|
||||
|
||||
@options = defaults_for_group($groups[$i]);
|
||||
|
||||
$mysqladmin_found= 1; # The default
|
||||
$mysqladmin_found= 0 if (!length($mysqladmin));
|
||||
$com = "$mysqladmin";
|
||||
$tmp = " -u $opt_user";
|
||||
if (defined($opt_password)) {
|
||||
my $pw= $opt_password;
|
||||
# Protect single quotes in password
|
||||
$pw =~ s/'/'"'"'/g;
|
||||
$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;
|
||||
}
|
||||
|
||||
# Return a list of option files which can be opened. Similar, but not
|
||||
# identical, to behavior of my_search_option_files()
|
||||
# TODO implement and use my_print_defaults --list-groups instead
|
||||
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};
|
||||
|
||||
return ('/etc/my.cnf',
|
||||
'/etc/mysql/my.cnf',
|
||||
'/usr/local/mysql/my.cnf',
|
||||
($ENV{MYSQL_HOME} ? "$ENV{MYSQL_HOME}/my.cnf" : undef),
|
||||
$opt{'extra-file'},
|
||||
($ENV{HOME} ? "$ENV{HOME}/.my.cnf" : undef));
|
||||
}
|
||||
|
||||
|
||||
# Takes a specification of GNRs (see --help), and returns a list of matching
|
||||
# groups which actually are mentioned in a relevant config file
|
||||
sub find_groups
|
||||
{
|
||||
my ($raw_gids) = @_;
|
||||
|
||||
my %gids;
|
||||
my @groups;
|
||||
|
||||
if (defined($raw_gids))
|
||||
{
|
||||
# Make a hash of the wanted group ids
|
||||
foreach my $raw_gid (split ',', $raw_gids)
|
||||
{
|
||||
# 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)
|
||||
{
|
||||
print "ABORT: Bad GNR: $raw_gid; see $my_progname --help\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foreach my $i ($start .. $end)
|
||||
{
|
||||
# Use $i + 0 to normalize numbers (002 + 0 -> 2)
|
||||
$gids{$i + 0}= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my %seen;
|
||||
my @defaults_files = list_defaults_files();
|
||||
while (@defaults_files)
|
||||
{
|
||||
my $file = shift @defaults_files;
|
||||
next unless defined $file and not $seen{$file}++ and open CONF, '<', $file;
|
||||
|
||||
while (<CONF>)
|
||||
{
|
||||
if (/^\s*\[\s*(mysqld)(\d+)\s*\]\s*$/)
|
||||
{
|
||||
#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";
|
||||
}
|
||||
}
|
||||
elsif (/^\s*!include\s+(\S.*?)\s*$/)
|
||||
{
|
||||
push @defaults_files, $1;
|
||||
}
|
||||
elsif (/^\s*!includedir\s+(\S.*?)\s*$/)
|
||||
{
|
||||
push @defaults_files, <$1/*.cnf>;
|
||||
}
|
||||
}
|
||||
|
||||
close CONF;
|
||||
}
|
||||
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);
|
||||
|
||||
# If the argument is not 'my_print_defaults' then it would be of the format
|
||||
# <absolute_path>/<program>
|
||||
return $command if ($command ne 'my_print_defaults' && -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 /usr/local/mysql/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/mysql/bin/mysqld_safe
|
||||
mysqladmin = /usr/local/mysql/bin/mysqladmin
|
||||
user = multi_admin
|
||||
password = my_password
|
||||
|
||||
[mysqld2]
|
||||
socket = /tmp/mysql.sock2
|
||||
port = 3307
|
||||
pid-file = /usr/local/mysql/data2/hostname.pid2
|
||||
datadir = /usr/local/mysql/data2
|
||||
language = /usr/local/mysql/share/mysql/english
|
||||
user = unix_user1
|
||||
|
||||
[mysqld3]
|
||||
mysqld = /path/to/mysqld_safe
|
||||
ledir = /path/to/mysqld-binary/
|
||||
mysqladmin = /path/to/mysqladmin
|
||||
socket = /tmp/mysql.sock3
|
||||
port = 3308
|
||||
pid-file = /usr/local/mysql/data3/hostname.pid3
|
||||
datadir = /usr/local/mysql/data3
|
||||
language = /usr/local/mysql/share/mysql/swedish
|
||||
user = unix_user2
|
||||
|
||||
[mysqld4]
|
||||
socket = /tmp/mysql.sock4
|
||||
port = 3309
|
||||
pid-file = /usr/local/mysql/data4/hostname.pid4
|
||||
datadir = /usr/local/mysql/data4
|
||||
language = /usr/local/mysql/share/mysql/estonia
|
||||
user = unix_user3
|
||||
|
||||
[mysqld6]
|
||||
socket = /tmp/mysql.sock6
|
||||
port = 3311
|
||||
pid-file = /usr/local/mysql/data6/hostname.pid6
|
||||
datadir = /usr/local/mysql/data6
|
||||
language = /usr/local/mysql/share/mysql/japanese
|
||||
user = unix_user4
|
||||
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.
|
||||
|
||||
$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 --defaults-extra-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.
|
||||
|
||||
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 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.
|
||||
|
||||
Options:
|
||||
|
||||
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]}
|
||||
|
||||
--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);
|
||||
}
|
||||
955
database/bin/mysqld_safe
Executable file
955
database/bin/mysqld_safe
Executable file
|
|
@ -0,0 +1,955 @@
|
|||
#!/bin/sh
|
||||
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
|
||||
# This file is public domain and comes with NO WARRANTY of any kind
|
||||
#
|
||||
# Script to start the MySQL daemon and restart it if it dies unexpectedly
|
||||
#
|
||||
# This should be executed in the MySQL base directory if you are using a
|
||||
# binary installation that is not installed in its compile-time default
|
||||
# location
|
||||
#
|
||||
# mysql.server works by first doing a cd to the base directory and from there
|
||||
# executing mysqld_safe
|
||||
|
||||
# Initialize script globals
|
||||
KILL_MYSQLD=1;
|
||||
MYSQLD=
|
||||
niceness=0
|
||||
nowatch=0
|
||||
mysqld_ld_preload=
|
||||
mysqld_ld_library_path=
|
||||
flush_caches=0
|
||||
numa_interleave=0
|
||||
unsafe_my_cnf=0
|
||||
defaults_group_suffix=
|
||||
|
||||
# Initial logging status: error log is not open, and not using syslog
|
||||
logging=init
|
||||
want_syslog=0
|
||||
syslog_tag=
|
||||
user='mysql'
|
||||
pid_file=
|
||||
err_log=
|
||||
err_log_base=
|
||||
|
||||
syslog_tag_mysqld=mysqld
|
||||
syslog_tag_mysqld_safe=mysqld_safe
|
||||
|
||||
trap '' 1 2 3 15 # we shouldn't let anyone kill us
|
||||
|
||||
# MySQL-specific environment variable. First off, it's not really a umask,
|
||||
# it's the desired mode. Second, it follows umask(2), not umask(3) in that
|
||||
# octal needs to be explicit. Our shell might be a proper sh without printf,
|
||||
# multiple-base arithmetic, and binary arithmetic, so this will get ugly.
|
||||
# We reject decimal values to keep things at least half-sane.
|
||||
umask 007 # fallback
|
||||
UMASK="${UMASK-0640}"
|
||||
fmode=`echo "$UMASK" | sed -e 's/[^0246]//g'`
|
||||
octalp=`echo "$fmode"|cut -c1`
|
||||
fmlen=`echo "$fmode"|wc -c|sed -e 's/ //g'`
|
||||
if [ "x$octalp" != "x0" -o "x$UMASK" != "x$fmode" -o "x$fmlen" != "x5" ]
|
||||
then
|
||||
fmode=0640
|
||||
echo "UMASK must be a 3-digit mode with an additional leading 0 to indicate octal." >&2
|
||||
echo "The first digit will be corrected to 6, the others may be 0, 2, 4, or 6." >&2
|
||||
fi
|
||||
fmode=`echo "$fmode"|cut -c3-4`
|
||||
fmode="6$fmode"
|
||||
if [ "x$UMASK" != "x0$fmode" ]
|
||||
then
|
||||
echo "UMASK corrected from $UMASK to 0$fmode ..."
|
||||
fi
|
||||
|
||||
defaults=
|
||||
case "$1" in
|
||||
--no-defaults|--defaults-file=*|--defaults-extra-file=*)
|
||||
defaults="$1"; shift
|
||||
;;
|
||||
esac
|
||||
|
||||
usage () {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTIONS]
|
||||
--no-defaults Don't read the system defaults file
|
||||
--core-file-size=LIMIT Limit core files to the specified size
|
||||
--defaults-file=FILE Use the specified defaults file
|
||||
--defaults-extra-file=FILE Also use defaults from the specified file
|
||||
--ledir=DIRECTORY Look for mysqld in the specified directory
|
||||
--open-files-limit=LIMIT Limit the number of open files
|
||||
--crash-script=FILE Script to call when mysqld crashes
|
||||
--timezone=TZ Set the system timezone
|
||||
--malloc-lib=LIB Preload shared library LIB if available
|
||||
--mysqld=FILE Use the specified file as mysqld
|
||||
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
|
||||
--nice=NICE Set the scheduling priority of mysqld
|
||||
--no-auto-restart Exit after starting mysqld
|
||||
--nowatch Exit after starting mysqld
|
||||
--plugin-dir=DIR Plugins are under DIR or DIR/VERSION, if
|
||||
VERSION is given
|
||||
--skip-kill-mysqld Don't try to kill stray mysqld processes
|
||||
--syslog Log messages to syslog with 'logger'
|
||||
--skip-syslog Log messages to error log (default)
|
||||
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
|
||||
--flush-caches Flush and purge buffers/caches before
|
||||
starting the server
|
||||
--numa-interleave Run mysqld with its memory interleaved
|
||||
on all NUMA nodes
|
||||
|
||||
All other options are passed to the mysqld program.
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
my_which ()
|
||||
{
|
||||
save_ifs="${IFS-UNSET}"
|
||||
IFS=:
|
||||
ret=0
|
||||
for file
|
||||
do
|
||||
for dir in $PATH
|
||||
do
|
||||
if [ -f "$dir/$file" ]
|
||||
then
|
||||
echo "$dir/$file"
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
|
||||
ret=1 #signal an error
|
||||
break
|
||||
done
|
||||
|
||||
if [ "$save_ifs" = UNSET ]
|
||||
then
|
||||
unset IFS
|
||||
else
|
||||
IFS="$save_ifs"
|
||||
fi
|
||||
return $ret # Success
|
||||
}
|
||||
|
||||
find_in_bin() {
|
||||
if test -x "$MY_BASEDIR_VERSION/bin/$1"
|
||||
then
|
||||
echo "$MY_BASEDIR_VERSION/bin/$1"
|
||||
elif test -x "/usr/local/mysql/bin/$1"
|
||||
then
|
||||
echo "/usr/local/mysql/bin/$1"
|
||||
else
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
log_generic () {
|
||||
priority="$1"
|
||||
shift
|
||||
|
||||
msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*"
|
||||
echo "$msg"
|
||||
case $logging in
|
||||
init) ;; # Just echo the message, don't save it anywhere
|
||||
file) echo "$msg" | "$helper" "$user" log "$err_log" ;;
|
||||
syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;;
|
||||
*)
|
||||
echo "Internal program error (non-fatal):" \
|
||||
" unknown logging method '$logging'" >&2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
log_error () {
|
||||
log_generic daemon.error "$@" >&2
|
||||
}
|
||||
|
||||
log_notice () {
|
||||
log_generic daemon.notice "$@"
|
||||
}
|
||||
|
||||
eval_log_error () {
|
||||
cmd="$1"
|
||||
case $logging in
|
||||
file) cmd="$cmd 2>&1 | "`shell_quote_string "$helper"`" $user log "`shell_quote_string "$err_log"` ;;
|
||||
syslog)
|
||||
# mysqld often prefixes its messages with a timestamp, which is
|
||||
# redundant when logging to syslog (which adds its own timestamp)
|
||||
# However, we don't strip the timestamp with sed here, because
|
||||
# sed buffers output (only GNU sed supports a -u (unbuffered) option)
|
||||
# which means that messages may not get sent to syslog until the
|
||||
# mysqld process quits.
|
||||
cmd="$cmd 2>&1 | logger -t '$syslog_tag_mysqld' -p daemon.error"
|
||||
;;
|
||||
*)
|
||||
echo "Internal program error (non-fatal):" \
|
||||
" unknown logging method '$logging'" >&2
|
||||
;;
|
||||
esac
|
||||
|
||||
if test $nowatch -eq 1
|
||||
then
|
||||
# We'd prefer to exec $cmd here, but SELinux needs to be fixed first
|
||||
#/usr/bin/logger "Running mysqld: $cmd"
|
||||
eval "$cmd &"
|
||||
exit 0
|
||||
else
|
||||
#echo "Running mysqld: [$cmd]"
|
||||
eval "$cmd"
|
||||
fi
|
||||
}
|
||||
|
||||
shell_quote_string() {
|
||||
# This sed command makes sure that any special chars are quoted,
|
||||
# so the arg gets passed exactly to the server.
|
||||
echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g'
|
||||
}
|
||||
|
||||
check_executable_location() {
|
||||
if test "$unsafe_my_cnf" = 1 -a "$unrecognized_handling" != collect; then
|
||||
log_error "Cannot accept $1 from a config file, when my.cnf is in the datadir"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
parse_arguments() {
|
||||
for arg do
|
||||
# the parameter after "=", or the whole $arg if no match
|
||||
val=`echo "$arg" | sed -e 's;^--[^=]*=;;'`
|
||||
# what's before "=", or the whole $arg if no match
|
||||
optname=`echo "$arg" | sed -e 's/^\(--[^=]*\)=.*$/\1/'`
|
||||
# replace "_" by "-" ; mysqld_safe must accept "_" like mysqld does.
|
||||
optname_subst=`echo "$optname" | sed 's/_/-/g'`
|
||||
arg=`echo $arg | sed "s/^$optname/$optname_subst/"`
|
||||
case "$arg" in
|
||||
# these get passed explicitly to mysqld
|
||||
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
|
||||
--datadir=*|--data=*) DATADIR="$val" ;;
|
||||
--pid-file=*) pid_file="$val" ;;
|
||||
--plugin-dir=*) PLUGIN_DIR="$val" ;;
|
||||
--user=*) user="$val"; SET_USER=1 ;;
|
||||
--log-basename=*|--hostname=*|--loose-log-basename=*)
|
||||
pid_file="$val.pid";
|
||||
err_log_base="$val";
|
||||
;;
|
||||
|
||||
# these might have been set in a [mysqld_safe] section of my.cnf
|
||||
# they are added to mysqld command line to override settings from my.cnf
|
||||
--log-error=*) err_log="$val" ;;
|
||||
--port=*) mysql_tcp_port="$val" ;;
|
||||
--socket=*) mysql_unix_port="$val" ;;
|
||||
|
||||
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
|
||||
--core-file-size=*) core_file_size="$val" ;;
|
||||
--ledir=*) check_executable_location "$arg" ; ledir="$val" ;;
|
||||
--malloc-lib=*) check_executable_location "$arg"; set_malloc_lib "$val" ;;
|
||||
--crash-script=*) check_executable_location "$arg"; crash_script="$val" ;;
|
||||
--mysqld=*) check_executable_location "$arg"; MYSQLD="$val" ;;
|
||||
--mysqld-version=*)
|
||||
if test -n "$val"
|
||||
then
|
||||
check_executable_location "$arg"
|
||||
MYSQLD="mysqld-$val"
|
||||
PLUGIN_VARIANT="/$val"
|
||||
else
|
||||
MYSQLD="mysqld"
|
||||
fi
|
||||
;;
|
||||
--nice=*) niceness="$val" ;;
|
||||
--nowatch|--no-watch|--no-auto-restart) nowatch=1 ;;
|
||||
--open-files-limit=*) open_files="$val" ;;
|
||||
--open_files_limit=*) open_files="$val" ;;
|
||||
--skip-kill-mysqld*) KILL_MYSQLD=0 ;;
|
||||
--syslog) want_syslog=1 ;;
|
||||
--skip-syslog) want_syslog=0 ;;
|
||||
--syslog-tag=*) syslog_tag="$val" ;;
|
||||
--timezone=*) TZ="$val"; export TZ; ;;
|
||||
--flush-caches) flush_caches=1 ;;
|
||||
--numa-interleave) numa_interleave=1 ;;
|
||||
|
||||
--defaults-group-suffix=*) defaults_group_suffix="$arg" ;;
|
||||
|
||||
--help) usage ;;
|
||||
|
||||
*)
|
||||
case "$unrecognized_handling" in
|
||||
collect) append_arg_to_args "$arg" ;;
|
||||
complain) log_error "unknown option '$arg'" ;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# Add a single shared library to the list of libraries which will be added to
|
||||
# LD_PRELOAD for mysqld
|
||||
#
|
||||
# Since LD_PRELOAD is a space-separated value (for historical reasons), if a
|
||||
# shared lib's path contains spaces, that path will be prepended to
|
||||
# LD_LIBRARY_PATH and stripped from the lib value.
|
||||
add_mysqld_ld_preload() {
|
||||
lib_to_add="$1"
|
||||
log_notice "Adding '$lib_to_add' to LD_PRELOAD for mysqld"
|
||||
|
||||
case "$lib_to_add" in
|
||||
*' '*)
|
||||
# Must strip path from lib, and add it to LD_LIBRARY_PATH
|
||||
lib_file=`basename "$lib_to_add"`
|
||||
case "$lib_file" in
|
||||
*' '*)
|
||||
# The lib file itself has a space in its name, and can't
|
||||
# be used in LD_PRELOAD
|
||||
log_error "library name '$lib_to_add' contains spaces and can not be used with LD_PRELOAD"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
lib_path=`dirname "$lib_to_add"`
|
||||
lib_to_add="$lib_file"
|
||||
[ -n "$mysqld_ld_library_path" ] && mysqld_ld_library_path="$mysqld_ld_library_path:"
|
||||
mysqld_ld_library_path="$mysqld_ld_library_path$lib_path"
|
||||
;;
|
||||
esac
|
||||
|
||||
# LD_PRELOAD is a space-separated
|
||||
[ -n "$mysqld_ld_preload" ] && mysqld_ld_preload="$mysqld_ld_preload "
|
||||
mysqld_ld_preload="${mysqld_ld_preload}$lib_to_add"
|
||||
}
|
||||
|
||||
|
||||
# Returns LD_PRELOAD (and LD_LIBRARY_PATH, if needed) text, quoted to be
|
||||
# suitable for use in the eval that calls mysqld.
|
||||
#
|
||||
# All values in mysqld_ld_preload are prepended to LD_PRELOAD.
|
||||
mysqld_ld_preload_text() {
|
||||
text=
|
||||
|
||||
if [ -n "$mysqld_ld_preload" ]; then
|
||||
new_text="$mysqld_ld_preload"
|
||||
[ -n "$LD_PRELOAD" ] && new_text="$new_text $LD_PRELOAD"
|
||||
text="${text}LD_PRELOAD="`shell_quote_string "$new_text"`' '
|
||||
fi
|
||||
|
||||
if [ -n "$mysqld_ld_library_path" ]; then
|
||||
new_text="$mysqld_ld_library_path"
|
||||
[ -n "$LD_LIBRARY_PATH" ] && new_text="$new_text:$LD_LIBRARY_PATH"
|
||||
text="${text}LD_LIBRARY_PATH="`shell_quote_string "$new_text"`' '
|
||||
fi
|
||||
|
||||
echo "$text"
|
||||
}
|
||||
|
||||
|
||||
mysql_config=
|
||||
get_mysql_config() {
|
||||
if [ -z "$mysql_config" ]; then
|
||||
mysql_config=`echo "$0" | sed 's,/[^/][^/]*$,/mysql_config,'`
|
||||
if [ ! -x "$mysql_config" ]; then
|
||||
log_error "Can not run mysql_config $@ from '$mysql_config'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
"$mysql_config" "$@"
|
||||
}
|
||||
|
||||
|
||||
# set_malloc_lib LIB
|
||||
# - If LIB is empty, do nothing and return
|
||||
# - If LIB is 'tcmalloc', look for tcmalloc shared library in /usr/lib
|
||||
# then pkglibdir. tcmalloc is part of the Google perftools project.
|
||||
# - If LIB is an absolute path, assume it is a malloc shared library
|
||||
#
|
||||
# Put LIB in mysqld_ld_preload, which will be added to LD_PRELOAD when
|
||||
# running mysqld. See ld.so for details.
|
||||
set_malloc_lib() {
|
||||
malloc_lib="$1"
|
||||
|
||||
if [ "$malloc_lib" = tcmalloc ]; then
|
||||
pkglibdir=`get_mysql_config --variable=pkglibdir`
|
||||
malloc_lib=
|
||||
# This list is kept intentionally simple. Simply set --malloc-lib
|
||||
# to a full path if another location is desired.
|
||||
for libdir in /usr/lib "$pkglibdir" "$pkglibdir/mysql"; do
|
||||
for flavor in _minimal '' _and_profiler _debug; do
|
||||
tmp="$libdir/libtcmalloc$flavor.so"
|
||||
#log_notice "DEBUG: Checking for malloc lib '$tmp'"
|
||||
[ -r "$tmp" ] || continue
|
||||
malloc_lib="$tmp"
|
||||
break 2
|
||||
done
|
||||
done
|
||||
|
||||
if [ -z "$malloc_lib" ]; then
|
||||
log_error "no shared library for --malloc-lib=tcmalloc found in /usr/lib or $pkglibdir"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Allow --malloc-lib='' to override other settings
|
||||
[ -z "$malloc_lib" ] && return
|
||||
|
||||
case "$malloc_lib" in
|
||||
/*)
|
||||
if [ ! -r "$malloc_lib" ]; then
|
||||
log_error "--malloc-lib '$malloc_lib' can not be read and will not be used"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
log_error "--malloc-lib must be an absolute path or 'tcmalloc'; " \
|
||||
"ignoring value '$malloc_lib'"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
add_mysqld_ld_preload "$malloc_lib"
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# First, try to find BASEDIR and ledir (where mysqld is)
|
||||
#
|
||||
|
||||
MY_PWD=`dirname $0`
|
||||
MY_PWD=`cd "$MY_PWD"/.. && pwd`
|
||||
# Check for the directories we would expect from a binary release install
|
||||
if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION"
|
||||
then
|
||||
# BASEDIR is already overridden on command line. Do not re-set.
|
||||
|
||||
# Use BASEDIR to discover le.
|
||||
if test -x "$MY_BASEDIR_VERSION/libexec/mysqld"
|
||||
then
|
||||
ledir="$MY_BASEDIR_VERSION/libexec"
|
||||
elif test -x "$MY_BASEDIR_VERSION/sbin/mysqld"
|
||||
then
|
||||
ledir="$MY_BASEDIR_VERSION/sbin"
|
||||
else
|
||||
ledir="$MY_BASEDIR_VERSION/bin"
|
||||
fi
|
||||
elif test -x "$MY_PWD/bin/mysqld"
|
||||
then
|
||||
MY_BASEDIR_VERSION="$MY_PWD" # Where bin, share and data are
|
||||
ledir="$MY_PWD/bin" # Where mysqld is
|
||||
# Check for the directories we would expect from a source install
|
||||
elif test -x "$MY_PWD/libexec/mysqld"
|
||||
then
|
||||
MY_BASEDIR_VERSION="$MY_PWD" # Where libexec, share and var are
|
||||
ledir="$MY_PWD/libexec" # Where mysqld is
|
||||
elif test -x "$MY_PWD/sbin/mysqld"
|
||||
then
|
||||
MY_BASEDIR_VERSION="$MY_PWD" # Where sbin, share and var are
|
||||
ledir="$MY_PWD/sbin" # Where mysqld is
|
||||
# Since we didn't find anything, used the compiled-in defaults
|
||||
else
|
||||
MY_BASEDIR_VERSION='/usr/local/mysql'
|
||||
ledir='/usr/local/mysql/bin'
|
||||
fi
|
||||
|
||||
helper=`find_in_bin mysqld_safe_helper`
|
||||
print_defaults=`find_in_bin my_print_defaults`
|
||||
|
||||
#
|
||||
# Second, try to find the data directory
|
||||
#
|
||||
|
||||
# Try where the binary installs put it
|
||||
if test -d $MY_BASEDIR_VERSION/data/mysql
|
||||
then
|
||||
DATADIR=$MY_BASEDIR_VERSION/data
|
||||
if test -z "$defaults" -a -r "$DATADIR/my.cnf"
|
||||
then
|
||||
defaults="--defaults-extra-file=$DATADIR/my.cnf"
|
||||
fi
|
||||
# Next try where the source installs put it
|
||||
elif test -d $MY_BASEDIR_VERSION/var/mysql
|
||||
then
|
||||
DATADIR=$MY_BASEDIR_VERSION/var
|
||||
# Or just give up and use our compiled-in default
|
||||
else
|
||||
DATADIR=/usr/local/mysql/data
|
||||
fi
|
||||
|
||||
if test -z "$MYSQL_HOME"
|
||||
then
|
||||
if test -r "$MY_BASEDIR_VERSION/my.cnf" && test -r "$DATADIR/my.cnf"
|
||||
then
|
||||
log_error "WARNING: Found two instances of my.cnf -
|
||||
$MY_BASEDIR_VERSION/my.cnf and
|
||||
$DATADIR/my.cnf
|
||||
IGNORING $DATADIR/my.cnf"
|
||||
|
||||
MYSQL_HOME=$MY_BASEDIR_VERSION
|
||||
elif test -r "$DATADIR/my.cnf"
|
||||
then
|
||||
log_error "WARNING: Found $DATADIR/my.cnf
|
||||
The data directory is a deprecated location for my.cnf, please move it to
|
||||
$MY_BASEDIR_VERSION/my.cnf"
|
||||
unsafe_my_cnf=1
|
||||
MYSQL_HOME=$DATADIR
|
||||
else
|
||||
MYSQL_HOME=$MY_BASEDIR_VERSION
|
||||
fi
|
||||
fi
|
||||
export MYSQL_HOME
|
||||
|
||||
append_arg_to_args () {
|
||||
args="$args "`shell_quote_string "$1"`
|
||||
}
|
||||
|
||||
args=
|
||||
|
||||
# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
|
||||
# and then merge with the command line arguments
|
||||
|
||||
SET_USER=2
|
||||
parse_arguments `$print_defaults $defaults --loose-verbose --mysqld`
|
||||
if test $SET_USER -eq 2
|
||||
then
|
||||
SET_USER=0
|
||||
fi
|
||||
|
||||
# If arguments come from [mysqld_safe] section of my.cnf
|
||||
# we complain about unrecognized options
|
||||
unrecognized_handling=complain
|
||||
parse_arguments `$print_defaults $defaults --loose-verbose mysqld_safe safe_mysqld mariadb_safe`
|
||||
|
||||
# We only need to pass arguments through to the server if we don't
|
||||
# handle them here. So, we collect unrecognized options (passed on
|
||||
# the command line) into the args variable.
|
||||
unrecognized_handling=collect
|
||||
parse_arguments "$@"
|
||||
|
||||
|
||||
#
|
||||
# Try to find the plugin directory
|
||||
#
|
||||
|
||||
# Use user-supplied argument
|
||||
if [ -n "${PLUGIN_DIR}" ]; then
|
||||
plugin_dir="${PLUGIN_DIR}"
|
||||
else
|
||||
# Try to find plugin dir relative to basedir
|
||||
for dir in lib64/mysql/plugin lib64/plugin lib/mysql/plugin lib/plugin
|
||||
do
|
||||
if [ -d "${MY_BASEDIR_VERSION}/${dir}" ]; then
|
||||
plugin_dir="${MY_BASEDIR_VERSION}/${dir}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
# Give up and use compiled-in default
|
||||
if [ -z "${plugin_dir}" ]; then
|
||||
plugin_dir='/usr/local/mysql/lib/plugin'
|
||||
fi
|
||||
fi
|
||||
plugin_dir="${plugin_dir}${PLUGIN_VARIANT}"
|
||||
|
||||
# Determine what logging facility to use
|
||||
|
||||
# Ensure that 'logger' exists, if it's requested
|
||||
if [ $want_syslog -eq 1 ]
|
||||
then
|
||||
my_which logger > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$err_log" -o $want_syslog -eq 0 ]
|
||||
then
|
||||
if [ -n "$err_log" ]
|
||||
then
|
||||
# mysqld adds ".err" if there is no extension on the --log-error
|
||||
# argument; must match that here, or mysqld_safe will write to a
|
||||
# different log file than mysqld
|
||||
|
||||
# mysqld does not add ".err" to "--log-error=foo."; it considers a
|
||||
# trailing "." as an extension
|
||||
|
||||
if expr "$err_log" : '.*\.[^/]*$' > /dev/null
|
||||
then
|
||||
:
|
||||
else
|
||||
err_log="$err_log".err
|
||||
fi
|
||||
|
||||
case "$err_log" in
|
||||
/* ) ;;
|
||||
* ) err_log="$DATADIR/$err_log" ;;
|
||||
esac
|
||||
else
|
||||
if [ -n "$err_log_base" ]
|
||||
then
|
||||
err_log=$err_log_base.err
|
||||
case "$err_log" in
|
||||
/* ) ;;
|
||||
* ) err_log="$DATADIR/$err_log" ;;
|
||||
esac
|
||||
else
|
||||
err_log=$DATADIR/`hostname`.err
|
||||
fi
|
||||
fi
|
||||
|
||||
append_arg_to_args "--log-error=$err_log"
|
||||
|
||||
if [ $want_syslog -eq 1 ]
|
||||
then
|
||||
# User explicitly asked for syslog, so warn that it isn't used
|
||||
log_error "Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect."
|
||||
want_syslog=0
|
||||
fi
|
||||
|
||||
# Log to err_log file
|
||||
log_notice "Logging to '$err_log'."
|
||||
logging=file
|
||||
|
||||
else
|
||||
if [ -n "$syslog_tag" ]
|
||||
then
|
||||
# Sanitize the syslog tag
|
||||
syslog_tag=`echo "$syslog_tag" | sed -e 's/[^a-zA-Z0-9_-]/_/g'`
|
||||
syslog_tag_mysqld_safe="${syslog_tag_mysqld_safe}-$syslog_tag"
|
||||
syslog_tag_mysqld="${syslog_tag_mysqld}-$syslog_tag"
|
||||
fi
|
||||
log_notice "Logging to syslog."
|
||||
logging=syslog
|
||||
fi
|
||||
|
||||
USER_OPTION=""
|
||||
if test -w / -o "$USER" = "root"
|
||||
then
|
||||
if test "$user" != "root" -o $SET_USER = 1
|
||||
then
|
||||
USER_OPTION="--user=$user"
|
||||
fi
|
||||
if test -n "$open_files"
|
||||
then
|
||||
ulimit -n $open_files
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "$open_files"
|
||||
then
|
||||
append_arg_to_args "--open-files-limit=$open_files"
|
||||
fi
|
||||
|
||||
safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-/tmp/mysql.sock}}
|
||||
# Make sure that directory for $safe_mysql_unix_port exists
|
||||
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
|
||||
if [ ! -d $mysql_unix_port_dir ]
|
||||
then
|
||||
if ! `mkdir -p $mysql_unix_port_dir`
|
||||
then
|
||||
log_error "Fatal error Can't create database directory '$mysql_unix_port'"
|
||||
exit 1
|
||||
fi
|
||||
chown $user $mysql_unix_port_dir
|
||||
chmod 755 $mysql_unix_port_dir
|
||||
fi
|
||||
|
||||
# If the user doesn't specify a binary, we assume name "mysqld"
|
||||
if test -z "$MYSQLD"
|
||||
then
|
||||
MYSQLD=mysqld
|
||||
fi
|
||||
|
||||
if test ! -x "$ledir/$MYSQLD"
|
||||
then
|
||||
log_error "The file $ledir/$MYSQLD
|
||||
does not exist or is not executable. Please cd to the mysql installation
|
||||
directory and restart this script from there as follows:
|
||||
./bin/mysqld_safe&
|
||||
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$pid_file"
|
||||
then
|
||||
pid_file="`hostname`.pid"
|
||||
fi
|
||||
# MariaDB wants pid file without datadir
|
||||
append_arg_to_args "--pid-file=$pid_file"
|
||||
case "$pid_file" in
|
||||
/* ) ;;
|
||||
* ) pid_file="$DATADIR/$pid_file" ;;
|
||||
esac
|
||||
|
||||
if test -n "$mysql_unix_port"
|
||||
then
|
||||
append_arg_to_args "--socket=$mysql_unix_port"
|
||||
fi
|
||||
if test -n "$mysql_tcp_port"
|
||||
then
|
||||
append_arg_to_args "--port=$mysql_tcp_port"
|
||||
fi
|
||||
|
||||
if test $niceness -eq 0
|
||||
then
|
||||
NOHUP_NICENESS="nohup"
|
||||
else
|
||||
NOHUP_NICENESS="nohup nice -$niceness"
|
||||
fi
|
||||
|
||||
# Using nice with no args to get the niceness level is GNU-specific.
|
||||
# This check could be extended for other operating systems (e.g.,
|
||||
# BSD could use "nohup sh -c 'ps -o nice -p $$' | tail -1").
|
||||
# But, it also seems that GNU nohup is the only one which messes
|
||||
# with the priority, so this is okay.
|
||||
if nohup nice > /dev/null 2>&1
|
||||
then
|
||||
normal_niceness=`nice`
|
||||
nohup_niceness=`nohup nice 2>/dev/null`
|
||||
|
||||
numeric_nice_values=1
|
||||
for val in $normal_niceness $nohup_niceness
|
||||
do
|
||||
case "$val" in
|
||||
-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | \
|
||||
[0-9] | [0-9][0-9] | [0-9][0-9][0-9] )
|
||||
;;
|
||||
* )
|
||||
numeric_nice_values=0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test $numeric_nice_values -eq 1
|
||||
then
|
||||
nice_value_diff=`expr $nohup_niceness - $normal_niceness`
|
||||
if test $? -eq 0 && test $nice_value_diff -gt 0 && \
|
||||
nice --$nice_value_diff echo testing > /dev/null 2>&1
|
||||
then
|
||||
# nohup increases the priority (bad), and we are permitted
|
||||
# to lower the priority with respect to the value the user
|
||||
# might have been given
|
||||
niceness=`expr $niceness - $nice_value_diff`
|
||||
NOHUP_NICENESS="nice -$niceness nohup"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if nohup echo testing > /dev/null 2>&1
|
||||
then
|
||||
:
|
||||
else
|
||||
# nohup doesn't work on this system
|
||||
NOHUP_NICENESS=""
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to set the core file size (even if we aren't root) because many systems
|
||||
# don't specify a hard limit on core file size.
|
||||
if test -n "$core_file_size"
|
||||
then
|
||||
ulimit -c $core_file_size
|
||||
fi
|
||||
|
||||
#
|
||||
# If there exists an old pid file, check if the daemon is already running
|
||||
# Note: The switches to 'ps' may depend on your operating system
|
||||
if test -f "$pid_file"
|
||||
then
|
||||
PID=`cat "$pid_file"`
|
||||
if kill -0 $PID > /dev/null 2> /dev/null
|
||||
then
|
||||
if ps wwwp $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null
|
||||
then # The pid contains a mysqld process
|
||||
log_error "A mysqld process already exists"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
rm -f "$pid_file"
|
||||
if test -f "$pid_file"
|
||||
then
|
||||
log_error "Fatal error: Can't remove the pid file:
|
||||
$pid_file
|
||||
Please remove it manually and start $0 again;
|
||||
mysqld daemon not started"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Flush and purge buffers/caches.
|
||||
#
|
||||
|
||||
if true && test $flush_caches -eq 1
|
||||
then
|
||||
# Locate sync, ensure it exists.
|
||||
if ! my_which sync > /dev/null 2>&1
|
||||
then
|
||||
log_error "sync command not found, required for --flush-caches"
|
||||
exit 1
|
||||
# Flush file system buffers.
|
||||
elif ! sync
|
||||
then
|
||||
# Huh, the sync() function is always successful...
|
||||
log_error "sync failed, check if sync is properly installed"
|
||||
fi
|
||||
|
||||
# Locate sysctl, ensure it exists.
|
||||
if ! my_which sysctl > /dev/null 2>&1
|
||||
then
|
||||
log_error "sysctl command not found, required for --flush-caches"
|
||||
exit 1
|
||||
# Purge page cache, dentries and inodes.
|
||||
elif ! sysctl -q -w vm.drop_caches=3
|
||||
then
|
||||
log_error "sysctl failed, check the error message for details"
|
||||
exit 1
|
||||
fi
|
||||
elif test $flush_caches -eq 1
|
||||
then
|
||||
log_error "--flush-caches is not supported on this platform"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Uncomment the following lines if you want all tables to be automatically
|
||||
# checked and repaired during startup. You should add sensible key_buffer
|
||||
# and sort_buffer values to my.cnf to improve check performance or require
|
||||
# less disk space.
|
||||
# Alternatively, you can start mysqld with the "myisam-recover" option. See
|
||||
# the manual for details.
|
||||
#
|
||||
# echo "Checking tables in $DATADIR"
|
||||
# $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check $DATADIR/*/*.MYI
|
||||
# $MY_BASEDIR_VERSION/bin/isamchk --silent --force $DATADIR/*/*.ISM
|
||||
|
||||
# Does this work on all systems?
|
||||
#if type ulimit | grep "shell builtin" > /dev/null
|
||||
#then
|
||||
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
|
||||
#fi
|
||||
|
||||
cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
|
||||
|
||||
#
|
||||
# Set mysqld's memory interleave policy.
|
||||
#
|
||||
|
||||
if true && test $numa_interleave -eq 1
|
||||
then
|
||||
# Locate numactl, ensure it exists.
|
||||
if ! my_which numactl > /dev/null 2>&1
|
||||
then
|
||||
log_error "numactl command not found, required for --numa-interleave"
|
||||
exit 1
|
||||
# Attempt to run a command, ensure it works.
|
||||
elif ! numactl --interleave=all true
|
||||
then
|
||||
log_error "numactl failed, check if numactl is properly installed"
|
||||
fi
|
||||
|
||||
# Launch mysqld with numactl.
|
||||
cmd="$cmd numactl --interleave=all"
|
||||
elif test $numa_interleave -eq 1
|
||||
then
|
||||
log_error "--numa-interleave is not supported on this platform"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for i in "$ledir/$MYSQLD" "$defaults_group_suffix" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
|
||||
"--datadir=$DATADIR" "--plugin-dir=$plugin_dir" "$USER_OPTION"
|
||||
do
|
||||
cmd="$cmd "`shell_quote_string "$i"`
|
||||
done
|
||||
cmd="$cmd $args"
|
||||
# Avoid 'nohup: ignoring input' warning
|
||||
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
|
||||
|
||||
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
|
||||
|
||||
# variable to track the current number of "fast" (a.k.a. subsecond) restarts
|
||||
fast_restart=0
|
||||
# maximum number of restarts before trottling kicks in
|
||||
max_fast_restarts=5
|
||||
# flag whether a usable sleep command exists
|
||||
have_sleep=1
|
||||
|
||||
# close stdout and stderr, everything goes to $logging now
|
||||
if expr "${-}" : '.*x' > /dev/null
|
||||
then
|
||||
:
|
||||
else
|
||||
exec 1>/dev/null
|
||||
exec 2>/dev/null
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
rm -f "$pid_file" # Some extra safety
|
||||
|
||||
start_time=`date +%M%S`
|
||||
|
||||
eval_log_error "$cmd"
|
||||
end_time=`date +%M%S`
|
||||
|
||||
if test ! -f "$pid_file" # This is removed if normal shutdown
|
||||
then
|
||||
break
|
||||
fi
|
||||
|
||||
|
||||
# sanity check if time reading is sane and there's sleep
|
||||
if test $end_time -gt 0 -a $have_sleep -gt 0
|
||||
then
|
||||
# throttle down the fast restarts
|
||||
if test $end_time -eq $start_time
|
||||
then
|
||||
fast_restart=`expr $fast_restart + 1`
|
||||
if test $fast_restart -ge $max_fast_restarts
|
||||
then
|
||||
log_notice "The server is respawning too fast. Sleeping for 1 second."
|
||||
sleep 1
|
||||
sleep_state=$?
|
||||
if test $sleep_state -gt 0
|
||||
then
|
||||
log_notice "The server is respawning too fast and no working sleep command. Turning off trottling."
|
||||
have_sleep=0
|
||||
fi
|
||||
|
||||
fast_restart=0
|
||||
fi
|
||||
else
|
||||
fast_restart=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if true && test $KILL_MYSQLD -eq 1
|
||||
then
|
||||
# Test if one process was hanging.
|
||||
# This is only a fix for Linux (running as base 3 mysqld processes)
|
||||
# but should work for the rest of the servers.
|
||||
# The only thing is ps x => redhat 5 gives warnings when using ps -x.
|
||||
# kill -9 is used or the process won't react on the kill.
|
||||
numofproces=`ps xaww | grep -v "grep" | grep "$ledir/$MYSQLD\>" | grep -c "pid-file=$pid_file"`
|
||||
|
||||
log_notice "Number of processes running now: $numofproces"
|
||||
I=1
|
||||
while test "$I" -le "$numofproces"
|
||||
do
|
||||
PROC=`ps xaww | grep "$ledir/$MYSQLD\>" | grep -v "grep" | grep "pid-file=$pid_file" | sed -n '$p'`
|
||||
|
||||
for T in $PROC
|
||||
do
|
||||
break
|
||||
done
|
||||
# echo "TEST $I - $T **"
|
||||
if kill -9 $T
|
||||
then
|
||||
log_error "$MYSQLD process hanging, pid $T - killed"
|
||||
else
|
||||
break
|
||||
fi
|
||||
I=`expr $I + 1`
|
||||
done
|
||||
fi
|
||||
log_notice "mysqld restarted"
|
||||
if test -n "$crash_script"
|
||||
then
|
||||
crash_script_output=`$crash_script 2>&1`
|
||||
log_error "$crash_script_output"
|
||||
fi
|
||||
done
|
||||
|
||||
log_notice "mysqld from pid file $pid_file ended"
|
||||
BIN
database/bin/mysqld_safe_helper
Executable file
BIN
database/bin/mysqld_safe_helper
Executable file
Binary file not shown.
BIN
database/bin/mysqldump
Executable file
BIN
database/bin/mysqldump
Executable file
Binary file not shown.
228
database/bin/mysqldumpslow
Executable file
228
database/bin/mysqldumpslow
Executable file
|
|
@ -0,0 +1,228 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; version 2
|
||||
# of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1335 USA
|
||||
|
||||
# mysqldumpslow - parse and summarize the MySQL slow query log
|
||||
|
||||
# Original version by Tim Bunce, sometime in 2000.
|
||||
# Further changes by Tim Bunce, 8th March 2001.
|
||||
# Handling of strings with \ and double '' by Monty 11 Aug 2001.
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
# t=time, l=lock time, r=rows
|
||||
# at, al, and ar are the corresponding averages
|
||||
|
||||
my %opt = (
|
||||
s => 'at',
|
||||
h => '*',
|
||||
);
|
||||
|
||||
GetOptions(\%opt,
|
||||
'v|verbose+',# verbose
|
||||
'help+', # write usage info
|
||||
'd|debug+', # debug
|
||||
's=s', # what to sort by (al, at, ar, ae, c, t, l, r, e)
|
||||
'r!', # reverse the sort order (largest last instead of first)
|
||||
't=i', # just show the top n queries
|
||||
'a!', # don't abstract all numbers to N and strings to 'S'
|
||||
'n=i', # abstract numbers with at least n digits within names
|
||||
'g=s', # grep: only consider stmts that include this string
|
||||
'h=s', # hostname/basename of db server for *-slow.log filename (can be wildcard)
|
||||
'i=s', # name of server instance (if using mysql.server startup script)
|
||||
'l!', # don't subtract lock time from total time
|
||||
) or usage("bad option");
|
||||
|
||||
$opt{'help'} and usage();
|
||||
|
||||
unless (@ARGV) {
|
||||
my $defaults = `my_print_defaults --mysqld`;
|
||||
|
||||
my $datadir = ($defaults =~ m/--datadir=(.*)/g)[-1];
|
||||
if (!$datadir or $opt{i}) {
|
||||
# determine the datadir from the instances section of /etc/my.cnf, if any
|
||||
my $instances = `my_print_defaults instances`;
|
||||
die "Can't determine datadir from 'my_print_defaults instances' output: $defaults"
|
||||
unless $instances;
|
||||
my @instances = ($instances =~ m/^--(\w+)-/mg);
|
||||
die "No -i 'instance_name' specified to select among known instances: @instances.\n"
|
||||
unless $opt{i};
|
||||
die "Instance '$opt{i}' is unknown (known instances: @instances)\n"
|
||||
unless grep { $_ eq $opt{i} } @instances;
|
||||
$datadir = ($instances =~ m/--$opt{i}-datadir=(.*)/g)[-1]
|
||||
or die "Can't determine --$opt{i}-datadir from 'my_print_defaults instances' output: $instances";
|
||||
warn "datadir=$datadir\n" if $opt{v};
|
||||
}
|
||||
|
||||
my $slowlog = ($defaults =~ m/--log[-_]slow[-_]queries=(.*)/g)[-1];
|
||||
if (!$slowlog)
|
||||
{
|
||||
$slowlog = ($defaults =~ m/--slow[-_]query[-_]log[-_]file=(.*)/g)[-1];
|
||||
}
|
||||
if ( $slowlog )
|
||||
{
|
||||
@ARGV = ($slowlog);
|
||||
die "Can't find '$slowlog'\n" unless @ARGV;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$opt{h})
|
||||
{
|
||||
$opt{h}= ($defaults =~ m/--log[-_]basename=(.*)/g)[-1];
|
||||
}
|
||||
@ARGV = <$datadir/$opt{h}-slow.log>;
|
||||
die "Can't find '$datadir/$opt{h}-slow.log'\n" unless @ARGV;
|
||||
}
|
||||
}
|
||||
|
||||
warn "\nReading mysql slow query log from @ARGV\n";
|
||||
|
||||
my @pending;
|
||||
my %stmt;
|
||||
$/ = ";\n#"; # read entire statements using paragraph mode
|
||||
while ( defined($_ = shift @pending) or defined($_ = <>) ) {
|
||||
warn "[[$_]]\n" if $opt{d}; # show raw paragraph being read
|
||||
|
||||
my @chunks = split /^\/.*Version.*started with[\000-\377]*?Time.*Id.*Command.*Argument.*\n/m;
|
||||
if (@chunks > 1) {
|
||||
unshift @pending, map { length($_) ? $_ : () } @chunks;
|
||||
warn "<<".join(">>\n<<",@chunks).">>" if $opt{d};
|
||||
next;
|
||||
}
|
||||
|
||||
s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
|
||||
my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
|
||||
|
||||
s/^# Thread_id: [0-9]+\s+Schema: [^\n]+\n//;
|
||||
s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+)\s+Rows_examined: ([0-9.]+).*\n//;
|
||||
my ($t, $l, $r, $e) = ($1, $2, $3, $4);
|
||||
|
||||
$t -= $l unless $opt{l};
|
||||
|
||||
# remove fluff that mysqld writes to log when it (re)starts:
|
||||
s!^/.*Version.*started with:.*\n!!mg;
|
||||
s!^Tcp port: \d+ Unix socket: \S+\n!!mg;
|
||||
s!^Time.*Id.*Command.*Argument.*\n!!mg;
|
||||
|
||||
# Remove optimizer info
|
||||
s!^# QC_Hit: \S+\s+Full_scan: \S+\s+Full_join: \S+\s+Tmp_table: \S+\s+Tmp_table_on_disk: \S+[^\n]+\n!!mg;
|
||||
s!^# Filesort: \S+\s+Filesort_on_disk: \S+[^\n]+\n!!mg;
|
||||
s!^# Full_scan: \S+\s+Full_join: \S+[^\n]+\n!!mg;
|
||||
|
||||
s/^use \w+;\n//; # not consistently added
|
||||
s/^SET timestamp=\d+;\n//;
|
||||
|
||||
s/^[ ]*\n//mg; # delete blank lines
|
||||
s/^[ ]*/ /mg; # normalize leading whitespace
|
||||
s/\s*;\s*(#\s*)?$//; # remove trailing semicolon(+newline-hash)
|
||||
|
||||
next if $opt{g} and !m/$opt{g}/io;
|
||||
|
||||
unless ($opt{a}) {
|
||||
s/\b\d+\b/N/g;
|
||||
s/\b0x[0-9A-Fa-f]+\b/N/g;
|
||||
s/''/'S'/g;
|
||||
s/""/"S"/g;
|
||||
s/(\\')//g;
|
||||
s/(\\")//g;
|
||||
s/'[^']+'/'S'/g;
|
||||
s/"[^"]+"/"S"/g;
|
||||
# -n=8: turn log_20001231 into log_NNNNNNNN
|
||||
s/([a-z_]+)(\d{$opt{n},})/$1.('N' x length($2))/ieg if $opt{n};
|
||||
# abbreviate massive "in (...)" statements and similar
|
||||
s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg;
|
||||
}
|
||||
|
||||
my $s = $stmt{$_} ||= { users=>{}, hosts=>{} };
|
||||
$s->{c} += 1;
|
||||
$s->{t} += $t;
|
||||
$s->{l} += $l;
|
||||
$s->{r} += $r;
|
||||
$s->{e} += $e;
|
||||
$s->{users}->{$user}++ if $user;
|
||||
$s->{hosts}->{$host}++ if $host;
|
||||
|
||||
warn "{{$_}}\n\n" if $opt{d}; # show processed statement string
|
||||
}
|
||||
|
||||
foreach (keys %stmt) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t, $l, $r, $e) = @{ $v }{qw(c t l r e)};
|
||||
$v->{at} = $t / $c;
|
||||
$v->{al} = $l / $c;
|
||||
$v->{ar} = $r / $c;
|
||||
$v->{ae} = $e / $c;
|
||||
}
|
||||
|
||||
my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt;
|
||||
@sorted = @sorted[0 .. $opt{t}-1] if $opt{t};
|
||||
@sorted = reverse @sorted if $opt{r};
|
||||
|
||||
foreach (@sorted) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t,$at, $l,$al, $r,$ar,$e, $ae) = @{ $v }{qw(c t at l al r ar e ae)};
|
||||
my @users = keys %{$v->{users}};
|
||||
my $user = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users;
|
||||
my @hosts = keys %{$v->{hosts}};
|
||||
my $host = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts;
|
||||
printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows_sent=%.1f (%d), Rows_examined=%.1f (%d), $user\@$host\n%s\n\n",
|
||||
$c, $at,$t, $al,$l, $ar,$r, $ae, $e, $_;
|
||||
}
|
||||
|
||||
sub usage {
|
||||
my $str= shift;
|
||||
my $text= <<HERE;
|
||||
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
|
||||
|
||||
Parse and summarize the MySQL slow query log. Options are
|
||||
|
||||
--verbose verbose
|
||||
--debug debug
|
||||
--help write this text to standard output
|
||||
|
||||
-v verbose
|
||||
-d debug
|
||||
-s ORDER what to sort by (al, at, ar, ae, c, l, r, e, t), 'at' is default
|
||||
al: average lock time
|
||||
ar: average rows sent
|
||||
at: average query time
|
||||
c: count
|
||||
l: lock time
|
||||
r: rows sent
|
||||
t: query time
|
||||
-r reverse the sort order (largest last instead of first)
|
||||
-t NUM just show the top n queries
|
||||
-a don't abstract all numbers to N and strings to 'S'
|
||||
-n NUM abstract numbers with at least n digits within names
|
||||
-g PATTERN grep: only consider stmts that include this string
|
||||
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
|
||||
default is '*', i.e. match all
|
||||
-i NAME name of server instance (if using mysql.server startup script)
|
||||
-l don't subtract lock time from total time
|
||||
|
||||
HERE
|
||||
if ($str) {
|
||||
print STDERR "ERROR: $str\n\n";
|
||||
print STDERR $text;
|
||||
exit 1;
|
||||
} else {
|
||||
print $text;
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
1161
database/bin/mysqlhotcopy
Executable file
1161
database/bin/mysqlhotcopy
Executable file
File diff suppressed because it is too large
Load diff
BIN
database/bin/mysqlimport
Executable file
BIN
database/bin/mysqlimport
Executable file
Binary file not shown.
BIN
database/bin/mysqlshow
Executable file
BIN
database/bin/mysqlshow
Executable file
Binary file not shown.
BIN
database/bin/mysqlslap
Executable file
BIN
database/bin/mysqlslap
Executable file
Binary file not shown.
BIN
database/bin/mysqltest
Executable file
BIN
database/bin/mysqltest
Executable file
Binary file not shown.
BIN
database/bin/mysqltest_embedded
Executable file
BIN
database/bin/mysqltest_embedded
Executable file
Binary file not shown.
2468
database/bin/mytop
Executable file
2468
database/bin/mytop
Executable file
File diff suppressed because it is too large
Load diff
BIN
database/bin/perror
Executable file
BIN
database/bin/perror
Executable file
Binary file not shown.
BIN
database/bin/replace
Executable file
BIN
database/bin/replace
Executable file
Binary file not shown.
BIN
database/bin/resolve_stack_dump
Executable file
BIN
database/bin/resolve_stack_dump
Executable file
Binary file not shown.
BIN
database/bin/resolveip
Executable file
BIN
database/bin/resolveip
Executable file
Binary file not shown.
BIN
database/bin/tokuft_logprint
Executable file
BIN
database/bin/tokuft_logprint
Executable file
Binary file not shown.
BIN
database/bin/tokuftdump
Executable file
BIN
database/bin/tokuftdump
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue