mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Import changeset
This commit is contained in:
15
scripts/.cvsignore
Normal file
15
scripts/.cvsignore
Normal file
@@ -0,0 +1,15 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
make_binary_distribution
|
||||
msql2mysql
|
||||
mysql_config
|
||||
mysql_convert_table_format
|
||||
mysql_find_rows
|
||||
mysql_fix_privilege_tables
|
||||
mysql_install_db
|
||||
mysql_setpermission
|
||||
mysql_zap
|
||||
mysqlaccess
|
||||
mysqlbug
|
||||
mysqlhotcopy
|
||||
safe_mysqld
|
104
scripts/Makefile.am
Normal file
104
scripts/Makefile.am
Normal file
@@ -0,0 +1,104 @@
|
||||
# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
||||
#
|
||||
# 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; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
## Process this file with automake to create Makefile.in
|
||||
|
||||
bin_SCRIPTS = @server_scripts@ \
|
||||
msql2mysql \
|
||||
mysql_config \
|
||||
mysql_fix_privilege_tables \
|
||||
mysql_setpermission \
|
||||
mysql_zap \
|
||||
mysqlaccess \
|
||||
mysqlbug \
|
||||
mysql_convert_table_format \
|
||||
mysql_find_rows \
|
||||
mysqlhotcopy
|
||||
|
||||
EXTRA_SCRIPTS = make_binary_distribution.sh \
|
||||
msql2mysql.sh \
|
||||
mysql_config.sh \
|
||||
mysql_fix_privilege_tables.sh \
|
||||
mysql_install_db.sh \
|
||||
mysql_setpermission.sh \
|
||||
mysql_zap.sh \
|
||||
mysqlaccess.sh \
|
||||
mysqlbug.sh \
|
||||
mysql_convert_table_format.sh \
|
||||
mysql_find_rows.sh \
|
||||
mysqlhotcopy.sh \
|
||||
safe_mysqld.sh
|
||||
|
||||
EXTRA_DIST = $(EXTRA_SCRIPTS) \
|
||||
mysqlaccess.conf \
|
||||
mysqlbug
|
||||
|
||||
pkgdata_DATA = make_binary_distribution
|
||||
|
||||
# mysqlbug should be distributed built so that people can report build
|
||||
# failures with it.
|
||||
CLEANFILES = @server_scripts@ \
|
||||
make_binary_distribution \
|
||||
msql2mysql \
|
||||
mysql_fix_privilege_tables \
|
||||
mysql_setpermission \
|
||||
mysql_zap \
|
||||
mysqlaccess \
|
||||
mysql_convert_table_format \
|
||||
mysql_find_rows
|
||||
|
||||
SUPERCLEANFILES = mysqlbug
|
||||
|
||||
# We want the right version and configure comand line in mysqlbug
|
||||
mysqlbug: ${top_builddir}/config.status ${top_builddir}/config.cache mysqlbug.sh
|
||||
|
||||
SUFFIXES = .sh
|
||||
|
||||
.sh:
|
||||
@RM@ -f $@ $@-t
|
||||
@SED@ \
|
||||
-e 's!@''bindir''@!$(bindir)!g' \
|
||||
-e 's!@''scriptdir''@!$(bindir)!g' \
|
||||
-e 's!@''prefix''@!$(prefix)!g' \
|
||||
-e 's!@''datadir''@!$(datadir)!g' \
|
||||
-e 's!@''localstatedir''@!$(localstatedir)!g' \
|
||||
-e 's!@''libexecdir''@!$(libexecdir)!g' \
|
||||
-e 's!@''pkglibdir''@!$(pkglibdir)!g' \
|
||||
-e 's!@''pkgincludedir''@!$(pkgincludedir)!g' \
|
||||
-e 's!@''CC''@!@CC@!'\
|
||||
-e 's!@''CXX''@!@CXX@!'\
|
||||
-e 's!@''GXX''@!@GXX@!'\
|
||||
-e 's!@''PERL''@!@PERL@!' \
|
||||
-e 's!@''CFLAGS''@!@SAVE_CFLAGS@!'\
|
||||
-e 's!@''CXXFLAGS''@!@SAVE_CXXFLAGS@!'\
|
||||
-e 's!@''LDFLAGS''@!@SAVE_LDFLAGS@!'\
|
||||
-e 's!@''CLIENT_LIBS''@!@CLIENT_LIBS@!' \
|
||||
-e 's!@''VERSION''@!@VERSION@!' \
|
||||
-e 's!@''COMPILATION_COMMENT''@!@COMPILATION_COMMENT@!' \
|
||||
-e 's!@''MACHINE_TYPE''@!@MACHINE_TYPE@!' \
|
||||
-e 's!@''HOSTNAME''@!@HOSTNAME@!' \
|
||||
-e 's!@''SYSTEM_TYPE''@!@SYSTEM_TYPE@!' \
|
||||
-e 's!@''CHECK_PID''@!@CHECK_PID@!' \
|
||||
-e 's!@''FIND_PROC''@!@FIND_PROC@!' \
|
||||
-e 's!@''MYSQLD_DEFAULT_SWITCHES''@!@MYSQLD_DEFAULT_SWITCHES@!' \
|
||||
-e 's!@''MYSQL_UNIX_ADDR''@!@MYSQL_UNIX_ADDR@!' \
|
||||
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
|
||||
-e 's!@''IS_LINUX''@!@IS_LINUX@!' \
|
||||
-e "s!@""CONF_COMMAND""@!@CONF_COMMAND@!" \
|
||||
-e 's!@''MYSQLD_USER''@!@MYSQLD_USER@!' \
|
||||
$< > $@-t
|
||||
@CHMOD@ +x $@-t
|
||||
@MV@ $@-t $@
|
131
scripts/make_binary_distribution.sh
Executable file
131
scripts/make_binary_distribution.sh
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/bin/sh
|
||||
# The default path should be /usr/local
|
||||
|
||||
# Get some info from configure
|
||||
# chmod +x ./scripts/setsomevars
|
||||
|
||||
machine=@MACHINE_TYPE@
|
||||
system=@SYSTEM_TYPE@
|
||||
version=@VERSION@
|
||||
export machine system version
|
||||
SOURCE=`pwd`
|
||||
|
||||
# Save temporary distribution here (must be full path)
|
||||
TMP=/tmp
|
||||
if test $# -gt 0
|
||||
then
|
||||
TMP=$1
|
||||
fi
|
||||
|
||||
#make
|
||||
|
||||
# This should really be integrated with automake and not duplicate the
|
||||
# installation list.
|
||||
|
||||
BASE=$TMP/my_dist
|
||||
mkdir $BASE $BASE/bin $BASE/data $BASE/data/mysql $BASE/data/test \
|
||||
$BASE/include $BASE/lib $BASE/support-files $BASE/share $BASE/share/mysql \
|
||||
$BASE/tests $BASE/scripts $BASE/sql-bench
|
||||
|
||||
chmod o-rwx $BASE/data $BASE/data/*
|
||||
|
||||
for i in sql/ChangeLog COPYING COPYING.LIB README Docs/INSTALL-BINARY \
|
||||
Docs/manual.html Docs/manual.txt Docs/manual_toc.html
|
||||
do
|
||||
cp -p $i $BASE
|
||||
done
|
||||
|
||||
for i in extra/comp_err extra/replace extra/perror extra/resolveip \
|
||||
extra/my_print_defaults isam/isamchk isam/pack_isam myisam/myisamchk myisam/myisampack sql/mysqld sql/mysqlbinlog \
|
||||
client/mysql sql/mysqld client/mysqlshow client/mysqladmin client/mysqldump client/mysqlimport client/mysql-test \
|
||||
client/.libs/mysql client/.libs/mysqlshow client/.libs/mysqladmin client/.libs/mysqldump client/.libs/mysqlimport client/.libs/mysql-test
|
||||
do
|
||||
cp -p $i $BASE/bin
|
||||
done
|
||||
|
||||
cp -p config.h include/* $BASE/include
|
||||
rm $BASE/include/Makefile*; rm $BASE/include/*.in
|
||||
|
||||
cp -p tests/*.res tests/*.tst tests/*.pl $BASE/tests
|
||||
cp -p support-files/* $BASE/support-files
|
||||
cp -p libmysql/.libs/libmysqlclient.a libmysql/.libs/libmysqlclient.so* libmysql/libmysqlclient.* mysys/libmysys.a strings/libmystrings.a dbug/libdbug.a $BASE/lib
|
||||
cp -r -p sql/share/* $BASE/share/mysql; rm -f $BASE/share/mysql/Makefile* $BASE/share/mysql/*/*.OLD $BASE/share/CVS $BASE/share/*/CVS
|
||||
|
||||
cp -p scripts/* $BASE/bin
|
||||
rm -f $BASE/bin/Makefile* $BASE/bin/*.in $BASE/bin/*.sh $BASE/bin/mysql_install_db $BASE/bin/make_binary_distribution $BASE/bin/setsomevars $BASE/support-files/Makefile* $BASE/support-files/*.sh
|
||||
|
||||
$BASE/bin/replace \@localstatedir\@ ./data \@bindir\@ ./bin \@scriptdir\@ ./bin \@libexecdir\@ ./bin \@prefix\@ . < $SOURCE/scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db
|
||||
$BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \@MYSQLD_USER\@ root \@localstatedir\@ /usr/local/mysql/data < $SOURCE/support-files/mysql.server.sh > $BASE/support-files/mysql.server
|
||||
$BASE/bin/replace /my/gnu/bin/hostname /bin/hostname -- $BASE/bin/safe_mysqld
|
||||
|
||||
mv $BASE/support-files/binary-configure $BASE/configure
|
||||
chmod a+x $BASE/bin/* $BASE/scripts/* $BASE/support-files/mysql-* $BASE/configure
|
||||
cp -r -p sql-bench/* $BASE/sql-bench
|
||||
rm -f $BASE/sql-bench/*.sh $BASE/sql-bench/Makefile* $BASE/lib/*.la
|
||||
|
||||
# Change the distribution to a long descreptive name
|
||||
NEW_NAME=mysql-$version-$system-$machine
|
||||
BASE2=$TMP/$NEW_NAME
|
||||
rm -rf $BASE2
|
||||
mv $BASE $BASE2
|
||||
BASE=$BASE2
|
||||
#
|
||||
# If we are compiling with gcc, copy libgcc.a to the distribution as libmygcc.a
|
||||
#
|
||||
|
||||
if test "@GXX@" = "yes"
|
||||
then
|
||||
cd $BASE/lib
|
||||
gcclib=`@CC@ --print-libgcc-file`
|
||||
if test $? -ne 0
|
||||
then
|
||||
print "Warning: Couldn't find libgcc.a!"
|
||||
else
|
||||
cp -p $gcclib libmygcc.a
|
||||
fi
|
||||
cd $SOURCE
|
||||
fi
|
||||
|
||||
# This is needed to prefere gnu tar instead of tar because tar can't
|
||||
# always handle long filenames
|
||||
|
||||
PATH_DIRS=`echo $PATH | sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `
|
||||
which_1 ()
|
||||
{
|
||||
for cmd
|
||||
do
|
||||
for d in $PATH_DIRS
|
||||
do
|
||||
for file in $d/$cmd
|
||||
do
|
||||
if test -x $file -a ! -d $file
|
||||
then
|
||||
echo $file
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Create the result tar file
|
||||
#
|
||||
|
||||
tar=`which_1 gtar`
|
||||
if test "$?" = "1" -o "$tar" = ""
|
||||
then
|
||||
tar=tar
|
||||
fi
|
||||
|
||||
echo "Using $tar to create archive"
|
||||
cd $TMP
|
||||
$tar cvf $SOURCE/$NEW_NAME.tar $NEW_NAME
|
||||
cd $SOURCE
|
||||
echo "Compressing archive"
|
||||
gzip -9 $NEW_NAME.tar
|
||||
echo "Removing temporary directory"
|
||||
rm -rf $BASE
|
||||
|
||||
echo "$NEW_NAME.tar.gz created"
|
16
scripts/msql2mysql.sh
Normal file
16
scripts/msql2mysql.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 1979-1996 TcX AB & Monty Program KB & Detron HB
|
||||
#
|
||||
# This software is distributed with NO WARRANTY OF ANY KIND. No author or
|
||||
# distributor accepts any responsibility for the consequences of using it, or
|
||||
# for whether it serves any particular purpose or works at all, unless he or
|
||||
# she says so in writing. Refer to the Free Public License (the "License")
|
||||
# for full details.
|
||||
#
|
||||
# Every copy of this file must include a copy of the License, normally in a
|
||||
# plain ASCII text file named PUBLIC. The License grants you the right to
|
||||
# copy, modify and redistribute this file, but only under certain conditions
|
||||
# described in the License. Among other things, the License requires that
|
||||
# the copyright notice and this notice be preserved on all copies.
|
||||
|
||||
@bindir@/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 -- $*
|
74
scripts/mysql_config.sh
Normal file
74
scripts/mysql_config.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
||||
#
|
||||
# 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; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# This script reports various configuration settings that may be needed
|
||||
# when using the MySQL client library.
|
||||
|
||||
ldata='@localstatedir@'
|
||||
execdir='@libexecdir@'
|
||||
bindir='@bindir@'
|
||||
pkglibdir='@pkglibdir@'
|
||||
pkgincludedir='@pkgincludedir@'
|
||||
version='@VERSION@'
|
||||
socket='@MYSQL_UNIX_ADDR@'
|
||||
port='@MYSQL_TCP_PORT@'
|
||||
ldflags='@LDFLAGS@'
|
||||
client_libs='@CLIENT_LIBS@'
|
||||
|
||||
libs="$ldflags -L'$pkglibdir' -lmysqlclient $client_libs"
|
||||
cflags="-I'$pkgincludedir'"
|
||||
|
||||
usage () {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTIONS]
|
||||
Options:
|
||||
--cflags [$cflags]
|
||||
--libs [$libs]
|
||||
--socket [$socket]
|
||||
--port [$port]
|
||||
--version [$version]
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ! test $# -gt 0; then usage; fi
|
||||
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
--cflags) echo "$cflags" ;;
|
||||
--libs) echo "$libs" ;;
|
||||
--socket) echo "$socket" ;;
|
||||
--port) echo "$port" ;;
|
||||
--version) echo "$version" ;;
|
||||
*) 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
|
114
scripts/mysql_convert_table_format.sh
Executable file
114
scripts/mysql_convert_table_format.sh
Executable file
@@ -0,0 +1,114 @@
|
||||
#!@PERL@
|
||||
|
||||
# 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_type="MYISAM";
|
||||
$exit_status=0;
|
||||
|
||||
GetOptions("force","help","host=s","password=s","user=s","type=s","verbose","version") ||
|
||||
usage(0);
|
||||
usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
|
||||
$opt_database=shift(@ARGV);
|
||||
|
||||
if (uc($opt_type) eq "HEAP")
|
||||
{
|
||||
print "Converting to type HEAP would delete your tables; aborting\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$dbh = DBI->connect("DBI:mysql:$opt_database:$opt_host",
|
||||
$opt_user,
|
||||
$opt_password,
|
||||
{ PrintError => 0})
|
||||
|| die "Can't connect to database $opt_database: $DBI::errstr\n";
|
||||
|
||||
if ($#ARGV < 0)
|
||||
{
|
||||
# Fetch all table names from the database
|
||||
my ($sth,$row);
|
||||
$sth=$dbh->prepare("show tables");
|
||||
$sth->execute || die "Can't get tables from $opt_database; $DBI::errstr\n";
|
||||
while (($row = $sth->fetchrow_arrayref))
|
||||
{
|
||||
push(@ARGV,$row->[0]);
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
print "Converting tables:\n" if ($opt_verbose);
|
||||
foreach $table (@ARGV)
|
||||
{
|
||||
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_type))
|
||||
{
|
||||
print "$table is alread of type $opt_type; Ignored\n";
|
||||
next;
|
||||
}
|
||||
}
|
||||
print "converting $table\n" if ($opt_verbose);
|
||||
if (!$dbh->do("ALTER TABLE $table type=$opt_type"))
|
||||
{
|
||||
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 table types.
|
||||
|
||||
Usage: $0 database [tables]
|
||||
If no tables has been specifed, all tables in the database will be converted.
|
||||
|
||||
The following options are available:
|
||||
|
||||
--force
|
||||
Continue even if there is some error.
|
||||
|
||||
--help or --Information
|
||||
Shows this help
|
||||
|
||||
--host='host name' (Default $opt_host)
|
||||
Host name where the database server is located.
|
||||
|
||||
--password='password'
|
||||
Password for the current user.
|
||||
|
||||
--type='table-type'
|
||||
Converts tables to the given table type (Default: $opt_type)
|
||||
MySQL 3.23 supports at least the BDB, ISAM and MYISAM types.
|
||||
|
||||
--user='user_name'
|
||||
User name to log into the SQL server.
|
||||
|
||||
--verbose
|
||||
This is a test specific option that is only used when debugging a test.
|
||||
Print more information about what is going on.
|
||||
|
||||
--version
|
||||
Shows the version of this program.
|
||||
EOF
|
||||
exit(1);
|
||||
}
|
148
scripts/mysql_find_rows.sh
Executable file
148
scripts/mysql_find_rows.sh
Executable file
@@ -0,0 +1,148 @@
|
||||
#!@PERL@
|
||||
|
||||
$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 && /^\#/); # Skipp 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
|
||||
|
||||
TCX Datakonsult AB, by Monty.
|
||||
This software comes with NO WARRANTY: see the file PUBLIC for details.
|
||||
|
||||
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);
|
||||
}
|
110
scripts/mysql_fix_privilege_tables.sh
Normal file
110
scripts/mysql_fix_privilege_tables.sh
Normal file
@@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "This scripts updates the mysql.user, mysql.db, mysql.host and the"
|
||||
echo "mysql.func table to MySQL 3.22.14 and above."
|
||||
echo ""
|
||||
echo "This is needed if you want to use the new GRANT functions or"
|
||||
echo "want to use the more secure passwords."
|
||||
echo ""
|
||||
echo "If you get Access denied errors, you should run this script again"
|
||||
echo "and give the MySQL root user password as a argument!"
|
||||
|
||||
root_password="$1"
|
||||
host="localhost"
|
||||
|
||||
# Fix old password format, add File_priv and func table
|
||||
echo ""
|
||||
echo "If your tables are already up to date or partially up to date you will"
|
||||
echo "get some warnings about 'Duplicated column name' or"
|
||||
echo "'Table 'func' already exists'. You can safely ignore these!"
|
||||
|
||||
@bindir@/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
|
||||
alter table user change password password char(16) NOT NULL;
|
||||
alter table user add File_priv enum('N','Y') NOT NULL;
|
||||
CREATE TABLE func (
|
||||
name char(64) DEFAULT '' NOT NULL,
|
||||
ret tinyint(1) DEFAULT '0' NOT NULL,
|
||||
dl char(128) DEFAULT '' NOT NULL,
|
||||
type enum ('function','aggregate') NOT NULL,
|
||||
PRIMARY KEY (name)
|
||||
);
|
||||
END_OF_DATA
|
||||
echo ""
|
||||
|
||||
# Add the new grant colums
|
||||
|
||||
echo "Creating Grant Alter and Index privileges if they don't exists"
|
||||
echo "You can ignore any Duplicate column errors"
|
||||
@bindir@/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
|
||||
alter table user add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
||||
alter table host add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
||||
alter table db add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
|
||||
END_OF_DATA
|
||||
res=$?
|
||||
echo ""
|
||||
|
||||
# If the new grant columns didn't exists, copy File -> Grant
|
||||
# and Create -> Alter, Index, References
|
||||
|
||||
if test $res = 0
|
||||
then
|
||||
echo "Setting default privileges for the new grant, index and alter privileges"
|
||||
@bindir@/mysql --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
|
||||
UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
|
||||
UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
|
||||
UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
|
||||
END_OF_DATA
|
||||
echo ""
|
||||
fi
|
||||
|
||||
#
|
||||
# Create tables_priv and columns_priv if they don't exists
|
||||
#
|
||||
|
||||
echo "Creating the new table and column privilege tables"
|
||||
|
||||
@bindir@/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
|
||||
CREATE TABLE tables_priv (
|
||||
Host char(60) DEFAULT '' NOT NULL,
|
||||
Db char(60) DEFAULT '' NOT NULL,
|
||||
User char(16) DEFAULT '' NOT NULL,
|
||||
Table_name char(60) DEFAULT '' NOT NULL,
|
||||
Grantor char(77) DEFAULT '' NOT NULL,
|
||||
Timestamp timestamp(14),
|
||||
Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
|
||||
Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
|
||||
PRIMARY KEY (Host,Db,User,Table_name)
|
||||
);
|
||||
CREATE TABLE columns_priv (
|
||||
Host char(60) DEFAULT '' NOT NULL,
|
||||
Db char(60) DEFAULT '' NOT NULL,
|
||||
User char(16) DEFAULT '' NOT NULL,
|
||||
Table_name char(60) DEFAULT '' NOT NULL,
|
||||
Column_name char(59) DEFAULT '' NOT NULL,
|
||||
Timestamp timestamp(14),
|
||||
Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
|
||||
PRIMARY KEY (Host,Db,User,Table_name,Column_name)
|
||||
);
|
||||
END_OF_DATA
|
||||
|
||||
#
|
||||
# Name change of Type -> Column_priv from MySQL 3.22.12
|
||||
#
|
||||
|
||||
echo "Changing name of columns_priv.Type -> columns_priv.Column_priv"
|
||||
echo "You can ignore any errors from this"
|
||||
|
||||
@bindir@/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
|
||||
ALTER TABLE columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
|
||||
END_OF_DATA
|
||||
|
||||
#
|
||||
# Add the new 'type' column to the func table.
|
||||
#
|
||||
|
||||
echo "Fixing the func table"
|
||||
echo "You can ignore any Duplicate column errors"
|
||||
|
||||
@bindir@/mysql --user=root --password=$root_password mysql <<EOF
|
||||
alter table func add type enum ('function','aggregate') NOT NULL;
|
||||
EOF
|
342
scripts/mysql_install_db.sh
Normal file
342
scripts/mysql_install_db.sh
Normal file
@@ -0,0 +1,342 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 1997, 1998, 1999 TCX DataKonsult AB & Monty Program KB & Detron HB
|
||||
# For a more info consult the file COPYRIGHT distributed with this file
|
||||
|
||||
# This scripts creates the privilege tables db, host, user, tables_priv,
|
||||
# columns_priv in the mysql database, as well as the func table.
|
||||
#
|
||||
# All arguments (exept -IN-RPM as a first argument) to this script are
|
||||
# passed to mysqld
|
||||
|
||||
ldata=@localstatedir@
|
||||
execdir=@libexecdir@
|
||||
bindir=@bindir@
|
||||
force=0
|
||||
IN_RPM=0
|
||||
defaults=
|
||||
|
||||
# Are we doing an rpm install?
|
||||
if test "$1" = "-IN-RPM"; then IN_RPM=1; shift; fi
|
||||
if test "$1" = "--force"; then force=1; shift; fi
|
||||
|
||||
# Get mysqld/safe_mysqld options from /etc/my.cnf or ~/.my.cnf
|
||||
case "$1" in
|
||||
--no-defaults) defaults="$1"; conf=/nonexistent; shift ;;
|
||||
--defaults-file=*) defaults="$1"; conf=`echo "$1"|sed 's;^--defaults-file=;;'`; shift ;;
|
||||
*)
|
||||
if test -w /
|
||||
then
|
||||
conf=/etc/my.cnf
|
||||
else
|
||||
conf=$HOME/.my.cnf
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -f "$conf"
|
||||
then
|
||||
if grep "^datadir" $conf >/dev/null
|
||||
then
|
||||
ldata=`grep "^datadir" $conf | sed 's;^[^=]*=[ \t]*;;' | sed 's;[ \t]$;;'`
|
||||
fi
|
||||
if grep "^execdir" $conf >/dev/null
|
||||
then
|
||||
execdir=`grep "^execdir" $conf | sed 's;^[^=]*=[ \t]*;;' | sed 's;[ \t]$;;'`
|
||||
fi
|
||||
if grep "^bindir" $conf >/dev/null
|
||||
then
|
||||
bindir=`grep "^bindir" $conf | sed 's;^[^=]*=[ \t]*;;' | sed 's;[ \t]$;;'`
|
||||
fi
|
||||
if grep "^user" $conf >/dev/null
|
||||
then
|
||||
user=`grep "^user" $conf | sed 's;^[^=]*=[ \t]*;;' | sed 's;[ \t]$;;'`
|
||||
fi
|
||||
fi
|
||||
|
||||
for arg
|
||||
do
|
||||
case "$arg" in
|
||||
--basedir=*) basedir=`echo "$arg"|sed 's;^--basedir=;;'`; bindir="$basedir/bin"; execdir="$basedir/libexec" ;;
|
||||
--datadir=*) ldata=`echo "$arg"|sed 's;^--datadir=;;'` ;;
|
||||
--user=*) user=`echo "$arg"|sed 's;^--user=;;'` ;;
|
||||
esac
|
||||
done
|
||||
|
||||
mdata=$ldata/mysql
|
||||
|
||||
if test ! -x $execdir/mysqld
|
||||
then
|
||||
if test "$IN_RPM" -eq 1
|
||||
then
|
||||
echo "FATAL ERROR $execdir/mysqld not found!"
|
||||
exit 1
|
||||
else
|
||||
echo "Didn't find $execdir/mysqld"
|
||||
echo "You should do a 'make install' before executing this script"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# On IRIX hostname is in /usr/bsd so add this to the path
|
||||
PATH=$PATH:/usr/bsd
|
||||
hostname=`hostname` # Install this too in the user table
|
||||
|
||||
# Check if hostname is valid
|
||||
if test "$IN_RPM" -eq 0 -a $force -eq 0
|
||||
then
|
||||
resolved=`$bindir/resolveip $hostname 2>&1`
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
resolved=`$bindir/resolveip localhost 2>&1`
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Sorry, the host '$hostname' could not be looked up."
|
||||
echo "Please configure the 'hostname' command to return a correct hostname."
|
||||
echo "If you want to solve this at a later stage, restart this script with"
|
||||
echo "the --force option"
|
||||
exit 1
|
||||
fi
|
||||
echo "WARNING: Your libc libraries are not 100 % compatible with this MySQL version"
|
||||
echo "mysqld should work normally with the exception that host name resolving"
|
||||
echo "will not work. This means that you should use IP addresses instead"
|
||||
echo "of hostnames when specifying MySQL privileges !"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create database directories mysql & test
|
||||
if test "$IN_RPM" -eq 0
|
||||
then
|
||||
if test ! -d $ldata; then mkdir $ldata; chmod 700 $ldata ; fi
|
||||
if test ! -d $ldata/mysql; then mkdir $ldata/mysql; chmod 700 $ldata/mysql ; fi
|
||||
if test ! -d $ldata/test; then mkdir $ldata/test; chmod 700 $ldata/test ; fi
|
||||
if test -w / -a ! -z "$user"; then
|
||||
chown $user $ldata $ldata/mysql $ldata/test;
|
||||
fi
|
||||
fi
|
||||
|
||||
# Initialize variables
|
||||
c_d="" i_d=""
|
||||
c_h="" i_h=""
|
||||
c_u="" i_u=""
|
||||
c_f="" i_f=""
|
||||
c_t="" c_c=""
|
||||
|
||||
# Check for old tables
|
||||
if test ! -f $mdata/db.frm
|
||||
then
|
||||
echo "Creating db table"
|
||||
|
||||
# mysqld --bootstrap wants one command/line
|
||||
c_d="$c_d CREATE TABLE db ("
|
||||
c_d="$c_d Host char(60) DEFAULT '' NOT NULL,"
|
||||
c_d="$c_d Db char(64) DEFAULT '' NOT NULL,"
|
||||
c_d="$c_d User char(16) DEFAULT '' NOT NULL,"
|
||||
c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_d="$c_d PRIMARY KEY Host (Host,Db,User),"
|
||||
c_d="$c_d KEY User (User)"
|
||||
c_d="$c_d )"
|
||||
c_d="$c_d comment='Database privileges';"
|
||||
|
||||
i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
|
||||
INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');"
|
||||
fi
|
||||
|
||||
if test ! -f $mdata/host.frm
|
||||
then
|
||||
echo "Creating host table"
|
||||
|
||||
c_h="$c_h CREATE TABLE host ("
|
||||
c_h="$c_h Host char(60) DEFAULT '' NOT NULL,"
|
||||
c_h="$c_h Db char(64) DEFAULT '' NOT NULL,"
|
||||
c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_h="$c_h PRIMARY KEY Host (Host,Db)"
|
||||
c_h="$c_h )"
|
||||
c_h="$c_h comment='Host privileges; Merged with database privileges';"
|
||||
fi
|
||||
|
||||
if test ! -f $mdata/user.frm
|
||||
then
|
||||
echo "Creating user table"
|
||||
|
||||
c_u="$c_u CREATE TABLE user ("
|
||||
c_u="$c_u Host char(60) DEFAULT '' NOT NULL,"
|
||||
c_u="$c_u User char(16) DEFAULT '' NOT NULL,"
|
||||
c_u="$c_u Password char(16) DEFAULT '' NOT NULL,"
|
||||
c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
|
||||
c_u="$c_u PRIMARY KEY Host (Host,User)"
|
||||
c_u="$c_u )"
|
||||
c_u="$c_u comment='Users and global privileges';"
|
||||
|
||||
i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
|
||||
INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
|
||||
|
||||
REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
|
||||
REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
|
||||
|
||||
INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
|
||||
INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');"
|
||||
fi
|
||||
|
||||
if test ! -f $mdata/func.frm
|
||||
then
|
||||
echo "Creating func table"
|
||||
|
||||
c_f="$c_f CREATE TABLE func ("
|
||||
c_f="$c_f name char(64) DEFAULT '' NOT NULL,"
|
||||
c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL,"
|
||||
c_f="$c_f dl char(128) DEFAULT '' NOT NULL,"
|
||||
c_f="$c_f type enum ('function','aggregate') NOT NULL,"
|
||||
c_f="$c_f PRIMARY KEY (name)"
|
||||
c_f="$c_f )"
|
||||
c_f="$c_f comment='User defined functions';"
|
||||
fi
|
||||
|
||||
if test ! -f $mdata/tables_priv.frm
|
||||
then
|
||||
echo "Creating tables_priv table"
|
||||
|
||||
c_t="$c_t CREATE TABLE tables_priv ("
|
||||
c_t="$c_t Host char(60) DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t Db char(64) DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t User char(16) DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t Table_name char(60) DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t Timestamp timestamp(14),"
|
||||
c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
|
||||
c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name),"
|
||||
c_t="$c_t KEY Grantor (Grantor)"
|
||||
c_t="$c_t )"
|
||||
c_t="$c_t comment='Table privileges';"
|
||||
fi
|
||||
|
||||
if test ! -f $mdata/columns_priv.frm
|
||||
then
|
||||
echo "Creating columns_priv table"
|
||||
|
||||
c_c="$c_c CREATE TABLE columns_priv ("
|
||||
c_c="$c_c Host char(60) DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c Db char(64) DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c User char(16) DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c Column_name char(64) DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c Timestamp timestamp(14),"
|
||||
c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
|
||||
c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
|
||||
c_c="$c_c )"
|
||||
c_c="$c_c comment='Column privileges';"
|
||||
fi
|
||||
|
||||
if $execdir/mysqld $defaults --bootstrap --skip-grant-tables \
|
||||
--basedir=@prefix@ --datadir=$ldata "$@" << END_OF_DATA
|
||||
use mysql;
|
||||
$c_d
|
||||
$i_d
|
||||
|
||||
$c_h
|
||||
$i_h
|
||||
|
||||
$c_u
|
||||
$i_u
|
||||
|
||||
$c_f
|
||||
$i_f
|
||||
|
||||
$c_t
|
||||
$c_c
|
||||
END_OF_DATA
|
||||
then
|
||||
echo ""
|
||||
if test "$IN_RPM" -eq 0
|
||||
then
|
||||
echo "To start mysqld at boot time you have to copy support-files/mysql.server"
|
||||
echo "to the right place for your system"
|
||||
echo
|
||||
fi
|
||||
echo "PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !"
|
||||
echo "This is done with:"
|
||||
echo "$bindir/mysqladmin -u root -p password 'new-password'"
|
||||
echo "$bindir/mysqladmin -u root -h `hostname` -p password 'new-password'"
|
||||
echo "See the manual for more instructions."
|
||||
#
|
||||
# Print message about upgrading unless we have created a new db table.
|
||||
if test -z "$c_d"
|
||||
then
|
||||
echo
|
||||
echo "NOTE: If you are upgrading from a MySQL <= 3.22.10 you should run"
|
||||
echo "the $bindir/mysql_fix_privilege_tables. Otherwise you will not be"
|
||||
echo "able to use the new GRANT command!"
|
||||
fi
|
||||
echo
|
||||
if test -z "$IN_RPM"
|
||||
then
|
||||
echo "You can start the MySQL demon with:"
|
||||
echo "cd @prefix@ ; $bindir/safe_mysqld &"
|
||||
echo
|
||||
echo "You can test the MySQL demon with the benchmarks in the 'sql-bench' directory:"
|
||||
echo "cd sql-bench ; run-all-tests"
|
||||
echo
|
||||
fi
|
||||
echo "Please report any problems with the @scriptdir@/mysqlbug script!"
|
||||
echo
|
||||
echo "The latest information about MySQL is available on the web at"
|
||||
echo "http://www.mysql.com"
|
||||
echo "Support MySQL by buying support/licenses at http://www.mysql.com/license.htmy."
|
||||
echo
|
||||
exit 0
|
||||
else
|
||||
echo "Installation of grant tables failed!"
|
||||
echo
|
||||
echo "Examine the logs in $ldata for more information."
|
||||
echo "You can also try to start the mysqld demon with:"
|
||||
echo "$execdir/mysqld --skip-grant &"
|
||||
echo "You can use the command line tool"
|
||||
echo "$bindir/mysql to connect to the mysql"
|
||||
echo "database and look at the grant tables:"
|
||||
echo
|
||||
echo "shell> $bindir/mysql -u root mysql"
|
||||
echo "mysql> show tables"
|
||||
echo
|
||||
echo "Try 'mysqld --help' if you have problems with paths. Using --log"
|
||||
echo "gives you a log in $ldata that may be helpful."
|
||||
echo
|
||||
echo "The latest information about MySQL is available on the web at"
|
||||
echo "http://www.mysql.com"
|
||||
echo "Please consult the MySQL manual section: 'Problems running mysql_install_db',"
|
||||
echo "and the manual section that describes problems on your OS."
|
||||
echo "Another information source is the MySQL email archive."
|
||||
echo "Please check all of the above before mailing us!"
|
||||
echo "And if you do mail us, you MUST use the @scriptdir@/mysqlbug script!"
|
||||
exit 1
|
||||
fi
|
669
scripts/mysql_setpermission.sh
Executable file
669
scripts/mysql_setpermission.sh
Executable file
@@ -0,0 +1,669 @@
|
||||
#!@PERL@
|
||||
## Emacs, this is -*- perl -*- mode? :-)
|
||||
##
|
||||
## 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)
|
||||
|
||||
#### TODO
|
||||
#
|
||||
# empty ... suggestions ... mail them to me ...
|
||||
|
||||
|
||||
$version="1.2";
|
||||
|
||||
use DBI;
|
||||
use Getopt::Long;
|
||||
use strict;
|
||||
use vars qw($dbh $hostname $opt_user $opt_password $opt_help $opt_host
|
||||
$opt_socket $opt_port $host $version);
|
||||
|
||||
|
||||
$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 '')
|
||||
{
|
||||
$hostname = "localhost";
|
||||
}
|
||||
else
|
||||
{
|
||||
$hostname = $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=$hostname: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 a user.\n";
|
||||
print " 2. Add a database + user privilege for that database.\n";
|
||||
print " - user can do all except all admin functions\n";
|
||||
print " 3. Add user privilege for an existing database.\n";
|
||||
print " - user can do all except all admin functions\n";
|
||||
print " 4. Add user privilege for an existing database.\n";
|
||||
print " - user can do all except all admin functions + no create/drop\n";
|
||||
print " 5. Add user privilege for an existing database.\n";
|
||||
print " - user can do only selects (no update/delete/insert etc.)\n";
|
||||
print " 0. exit this program\n";
|
||||
print "\nMake your choice [1,2,3,4,5,0]: ";
|
||||
while (<STDIN>) {
|
||||
$answer = $_;
|
||||
chomp($answer);
|
||||
if ($answer =~ /1|2|3|4|5|0/) {
|
||||
&setpwd if ($answer == 1);
|
||||
&addall($answer) if ($answer =~ /^[2345]$/);
|
||||
if ($answer == 0) {
|
||||
print "Sorry, 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();
|
||||
$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
|
||||
my $sth = $dbh->do("create database $db") || $dbh->errstr;
|
||||
}
|
||||
|
||||
# select the privilege ....
|
||||
if (($todo == 2) || ($todo == 3))
|
||||
{
|
||||
$priv = "'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'";
|
||||
}
|
||||
elsif ($todo == 4)
|
||||
{
|
||||
$priv = "'Y','Y','Y','Y','N','N','N','Y','Y','Y'";
|
||||
}
|
||||
elsif ($todo == 5)
|
||||
{
|
||||
$priv = "'Y','N','N','N','N','N','N','N','N','N'";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Sorry, choice number $todo isn't known inside the program .. See ya\n";
|
||||
quit();
|
||||
}
|
||||
|
||||
my @hosts = split(/,/,$host);
|
||||
$user = $dbh->quote($user);
|
||||
$db = $dbh->quote($db);
|
||||
if ($pass eq '')
|
||||
{
|
||||
$pass = "''";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pass = "PASSWORD(". $dbh->quote($pass) . ")";
|
||||
}
|
||||
foreach my $key (@hosts)
|
||||
{
|
||||
my $key1 = $dbh->quote($key);
|
||||
my $sth = $dbh->prepare("select Host,User from user where Host = $key1 and User = $user") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
my @r = $sth->fetchrow_array;
|
||||
if ($r[0])
|
||||
{
|
||||
print "WARNING WARNING SKIPPING CREATE FOR USER $user AND HOST $key\n";
|
||||
print "Reason: entry already exists in the user table.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sth = $dbh->prepare("insert into user (Host,User,Password) values($key1,$user,$pass)") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
$sth->finish;
|
||||
}
|
||||
$sth = $dbh->prepare("INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES ($key1,$db,$user,$priv)") || die $dbh->errstr;
|
||||
$sth->execute || die $dbh->errstr;
|
||||
$sth->finish;
|
||||
}
|
||||
$dbh->do("flush privileges") || print "Can't load 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 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): ";
|
||||
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)
|
||||
{
|
||||
$good = 1;
|
||||
$db = $r[0];
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You must type something ...\nTry again: ";
|
||||
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 ($answer,$user);
|
||||
|
||||
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 ($answer,$good,$pass,$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 ($answer,$good,$host);
|
||||
|
||||
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);
|
||||
}
|
156
scripts/mysql_zap.sh
Executable file
156
scripts/mysql_zap.sh
Executable file
@@ -0,0 +1,156 @@
|
||||
#!@PERL@
|
||||
# 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';
|
||||
$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")
|
||||
{
|
||||
&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] pattern
|
||||
Options: -I or -? "info" -f "force" -t "test".
|
||||
|
||||
Version 1.0
|
||||
Kill processes with matches 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 and after that with signal 9.
|
||||
If -t is given the processes is 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";
|
||||
}
|
||||
}
|
45
scripts/mysqlaccess.conf
Executable file
45
scripts/mysqlaccess.conf
Executable file
@@ -0,0 +1,45 @@
|
||||
# ------------------------------------------------------------------------- #
|
||||
# MySQLaccess version 2.0p2 #
|
||||
# (c) Yves.Carlier@rug.ac.be, 1997 #
|
||||
# #
|
||||
# *** Configuration file *** #
|
||||
# #
|
||||
# -Default values read by mysqlaccess during initialisation. #
|
||||
# This file is looked for in #
|
||||
# 1) the current directory #
|
||||
# 2) /etc/ #
|
||||
# -Options given on the command-line override the values given in here #
|
||||
# -Given options can't be overruled by empty/blanc options!! #
|
||||
# ------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# ----------------#
|
||||
# Global settings #
|
||||
# --------------- #
|
||||
#$Param{'host'} = '';
|
||||
$Param{'user'} = 'nobody';
|
||||
$Param{'db'} = 'test';
|
||||
$Param{'password'} = 'foobar';
|
||||
$Param{'debug'} = 0;
|
||||
|
||||
# --------------------------#
|
||||
# Settings for Command-line #
|
||||
# ------------------------- #
|
||||
if ($CMD) {
|
||||
$Param{'superuser'} = 'root';
|
||||
$Param{'rhost'} = 'localhost';
|
||||
$Param{'spassword'} = '';
|
||||
$Param{'brief'} = 1;
|
||||
}
|
||||
|
||||
# ---------------------#
|
||||
# Settings for CGI-BIN #
|
||||
# -------------------- #
|
||||
if ($CGI) {
|
||||
$Param{'superuser'} = 'root';
|
||||
$Param{'rhost'} = 'localhost';
|
||||
$Param{'spassword'} = '';
|
||||
$Param{'table'} = 1;
|
||||
}
|
||||
|
||||
1; #to make require happy
|
3248
scripts/mysqlaccess.sh
Executable file
3248
scripts/mysqlaccess.sh
Executable file
File diff suppressed because it is too large
Load Diff
380
scripts/mysqlbug.sh
Executable file
380
scripts/mysqlbug.sh
Executable file
@@ -0,0 +1,380 @@
|
||||
#!/bin/sh
|
||||
# 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="@VERSION@"
|
||||
COMPILATION_COMMENT="@COMPILATION_COMMENT@"
|
||||
BUGmysql="mysql@lists.mysql.com"
|
||||
# This is set by configure
|
||||
COMP_ENV_INFO="CC='@CC@' CFLAGS='@CFLAGS@' CXX='@CXX@' CXXFLAGS='@CXXFLAGS@' LDFLAGS='@LDFLAGS@'"
|
||||
CONFIGURE_LINE="@CONF_COMMAND@"
|
||||
|
||||
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
|
||||
EDIT=emacs
|
||||
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"`
|
||||
>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_ENV_INFO" && echo "Compilation info: $COMP_ENV_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."
|
||||
cp $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 now is 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
|
591
scripts/mysqlhotcopy.sh
Executable file
591
scripts/mysqlhotcopy.sh
Executable file
@@ -0,0 +1,591 @@
|
||||
#!@PERL@
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use Data::Dumper;
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use DBI;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
mysqlhotcopy - fast on-line hot-backup utility for local MySQL databases
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
mysqlhotcopy db_name
|
||||
|
||||
mysqlhotcopy --suffix=_copy db_name_1 ... db_name_n
|
||||
|
||||
mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
|
||||
|
||||
WARNING: THIS IS VERY MUCH A FIRST-CUT ALPHA. Comments/patches welcome.
|
||||
|
||||
=cut
|
||||
|
||||
# Documentation continued at end of file
|
||||
|
||||
my $VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/o);
|
||||
|
||||
my $OPTIONS = <<"_OPTIONS";
|
||||
|
||||
Usage: $0 db_name new_db_name
|
||||
|
||||
-?, --help display this helpscreen and exit
|
||||
-u, --user=# user for database login if not current user
|
||||
-p, --password=# password to use when connecting to server
|
||||
-P, --port=# port to use when connecting to local server
|
||||
-S, --socket=# socket to use when connecting to local server
|
||||
|
||||
--allowold don't abort if target already exists (rename it _old)
|
||||
--keepold don't delete previous (now renamed) target when done
|
||||
--noindices don't copy index files
|
||||
--method=# method for copy (only "cp" currently supported)
|
||||
|
||||
-q, --quiet be silent except for errors
|
||||
--debug enable debug
|
||||
-n, --dryrun report actions without doing them
|
||||
|
||||
--regexp=# copy all databases with names matching regexp
|
||||
--suffix=# suffix for names of copied databases
|
||||
--checkpoint=# insert checkpoint entry into specified db.table
|
||||
--flushlog flush logs once all tables are locked
|
||||
_OPTIONS
|
||||
|
||||
sub usage {
|
||||
die @_, $OPTIONS;
|
||||
}
|
||||
|
||||
my %opt = (
|
||||
user => getpwuid($>),
|
||||
indices => 1, # for safety
|
||||
allowold => 0, # for safety
|
||||
keepold => 0,
|
||||
method => "cp",
|
||||
flushlog => 0,
|
||||
);
|
||||
Getopt::Long::Configure(qw(no_ignore_case)); # disambuguate -p and -P
|
||||
GetOptions( \%opt,
|
||||
"help",
|
||||
"user|u=s",
|
||||
"password|p=s",
|
||||
"port|P=s",
|
||||
"socket|S=s",
|
||||
"allowold!",
|
||||
"keepold!",
|
||||
"indices!",
|
||||
"method=s",
|
||||
"debug",
|
||||
"quiet|q",
|
||||
"mv!",
|
||||
"regexp=s",
|
||||
"suffix=s",
|
||||
"checkpoint=s",
|
||||
"flushlog",
|
||||
"dryrun|n",
|
||||
) or usage("Invalid option");
|
||||
|
||||
# @db_desc
|
||||
# ==========
|
||||
# a list of hash-refs containing:
|
||||
#
|
||||
# 'src' - name of the db to copy
|
||||
# 'target' - destination directory of the copy
|
||||
# 'tables' - array-ref to list of tables in the db
|
||||
# 'files' - array-ref to list of files to be copied
|
||||
#
|
||||
|
||||
my @db_desc = ();
|
||||
my $tgt_name = undef;
|
||||
|
||||
if ( $opt{regexp} || $opt{suffix} || @ARGV > 2 ) {
|
||||
$tgt_name = pop @ARGV unless ( exists $opt{suffix} );
|
||||
@db_desc = map { { 'src' => $_ } } @ARGV;
|
||||
}
|
||||
else {
|
||||
usage("Database name to hotcopy not specified") unless ( @ARGV );
|
||||
|
||||
@db_desc = ( { 'src' => $ARGV[0] } );
|
||||
if ( @ARGV == 2 ) {
|
||||
$tgt_name = $ARGV[1];
|
||||
}
|
||||
else {
|
||||
$opt{suffix} = "_copy";
|
||||
}
|
||||
}
|
||||
|
||||
my $mysqld_help;
|
||||
my %mysqld_vars;
|
||||
my $start_time = time;
|
||||
$0 = $1 if $0 =~ m:/([^/]+)$:;
|
||||
$opt{quiet} = 0 if $opt{debug};
|
||||
$opt{allowold} = 1 if $opt{keepold};
|
||||
|
||||
# --- connect to the database ---
|
||||
my $dsn = ";host=localhost";
|
||||
$dsn .= ";port=$opt{port}" if $opt{port};
|
||||
$dsn .= ";mysql_socket=$opt{socket}" if $opt{socket};
|
||||
|
||||
my $dbh = DBI->connect("dbi:mysql:$dsn", $opt{user}, $opt{password}, {
|
||||
RaiseError => 1,
|
||||
PrintError => 0,
|
||||
AutoCommit => 1,
|
||||
});
|
||||
|
||||
# --- check that checkpoint table exists if specified ---
|
||||
if ( $opt{checkpoint} ) {
|
||||
eval { $dbh->do( qq{ select time_stamp, src, dest, msg
|
||||
from $opt{checkpoint} where 1 != 1} );
|
||||
};
|
||||
|
||||
die "Error accessing Checkpoint table ($opt{checkpoint}): $@"
|
||||
if ( $@ );
|
||||
}
|
||||
|
||||
# --- get variables from database ---
|
||||
my $sth_vars = $dbh->prepare("show variables");
|
||||
$sth_vars->execute;
|
||||
while ( my ($var,$value) = $sth_vars->fetchrow_array ) {
|
||||
$mysqld_vars{ $var } = $value;
|
||||
}
|
||||
my $datadir = $mysqld_vars{datadir}
|
||||
|| die "datadir not in mysqld variables";
|
||||
$datadir =~ s:/$::;
|
||||
|
||||
|
||||
# --- get target path ---
|
||||
my $tgt_dirname;
|
||||
if ($tgt_name =~ m:^\w+$:) {
|
||||
$tgt_dirname = "$datadir/$tgt_name";
|
||||
}
|
||||
elsif ($tgt_name =~ m:/: || $tgt_name eq '.') {
|
||||
$tgt_dirname = $tgt_name;
|
||||
}
|
||||
elsif ( $opt{suffix} ) {
|
||||
print "copy suffix $opt{suffix}\n" unless $opt{quiet};
|
||||
}
|
||||
else {
|
||||
die "Target '$tgt_name' doesn't look like a database name or directory path.\n";
|
||||
}
|
||||
|
||||
# --- resolve database names from regexp ---
|
||||
if ( defined $opt{regexp} ) {
|
||||
my $sth_dbs = $dbh->prepare("show databases");
|
||||
$sth_dbs->execute;
|
||||
while ( my ($db_name) = $sth_dbs->fetchrow_array ) {
|
||||
push @db_desc, { 'src' => $db_name } if ( $db_name =~ m/$opt{regexp}/o );
|
||||
}
|
||||
}
|
||||
|
||||
# --- get list of tables to hotcopy ---
|
||||
|
||||
my $hc_locks = "";
|
||||
my $num_tables = 0;
|
||||
my $num_files = 0;
|
||||
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
my $db = $rdb->{src};
|
||||
eval { $dbh->do( "use $db" ); };
|
||||
die "Database '$db' not accessible: $@" if ( $@ );
|
||||
my @dbh_tables = $dbh->func( '_ListTables' );
|
||||
|
||||
my $db_dir = "$datadir/$db";
|
||||
opendir(DBDIR, $db_dir )
|
||||
or die "Cannot open dir '$db_dir': $!";
|
||||
|
||||
my @db_files = grep { /.+\.\w+$/ } readdir(DBDIR)
|
||||
or warn "'$db' is an empty database\n";
|
||||
|
||||
closedir( DBDIR );
|
||||
|
||||
unless ($opt{indices}) {
|
||||
@db_files = grep { not /\.(ISM|MYI)$/ } @db_files;
|
||||
}
|
||||
|
||||
$rdb->{files} = [ @db_files ];
|
||||
my @hc_tables = map { "$db.$_" } @dbh_tables;
|
||||
$rdb->{tables} = [ @hc_tables ];
|
||||
|
||||
$hc_locks .= ", " if ( length $hc_locks && @hc_tables );
|
||||
$hc_locks .= join ", ", map { "$_ READ" } @hc_tables;
|
||||
|
||||
$num_tables += scalar @hc_tables;
|
||||
$num_files += scalar @{$rdb->{files}};
|
||||
}
|
||||
|
||||
# --- resolve targets for copies ---
|
||||
|
||||
my @targets = ();
|
||||
|
||||
if (length $tgt_name ) {
|
||||
# explicit destination directory specified
|
||||
|
||||
# GNU `cp -r` error message
|
||||
die "copying multiple databases, but last argument ($tgt_name) is not a directory\n"
|
||||
if ( @db_desc > 1 && !(-e $tgt_name && -d $tgt_name ) );
|
||||
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
$rdb->{target} = "$tgt_name/$rdb->{src}";
|
||||
}
|
||||
}
|
||||
else {
|
||||
die "Error: expected \$opt{suffix} to exist" unless ( exists $opt{suffix} );
|
||||
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
$rdb->{target} = "$datadir/$rdb->{src}$opt{suffix}";
|
||||
}
|
||||
}
|
||||
|
||||
print Dumper( \@db_desc ) if ( $opt{debug} );
|
||||
|
||||
# --- bail out if all specified databases are empty ---
|
||||
|
||||
die "No tables to hot-copy" unless ( length $hc_locks );
|
||||
|
||||
# --- create target directories ---
|
||||
|
||||
my @existing = ();
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
push @existing, $rdb->{target} if ( -d $rdb->{target} );
|
||||
}
|
||||
|
||||
die "Can't hotcopy to '", join( "','", @existing ), "' because already exist and --allowold option not given.\n"
|
||||
if ( @existing && !$opt{allowold} );
|
||||
|
||||
retire_directory( @existing ) if ( @existing );
|
||||
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
my $tgt_dirpath = $rdb->{target};
|
||||
if ( $opt{dryrun} ) {
|
||||
print "mkdir $tgt_dirpath, 0750\n";
|
||||
}
|
||||
else {
|
||||
mkdir($tgt_dirpath, 0750)
|
||||
or die "Can't create '$tgt_dirpath': $!\n";
|
||||
}
|
||||
}
|
||||
|
||||
##############################
|
||||
# --- PERFORM THE HOT-COPY ---
|
||||
#
|
||||
# Note that we try to keep the time between the LOCK and the UNLOCK
|
||||
# as short as possible, and only start when we know that we should
|
||||
# be able to complete without error.
|
||||
|
||||
# read lock all the tables we'll be copying
|
||||
# in order to get a consistent snapshot of the database
|
||||
|
||||
if ( $opt{checkpoint} ) {
|
||||
# convert existing READ lock on checkpoint table into WRITE lock
|
||||
unless ( $hc_locks =~ s/$opt{checkpoint}\s+READ/$opt{checkpoint} WRITE/ ) {
|
||||
$hc_locks .= ", $opt{checkpoint} WRITE";
|
||||
}
|
||||
}
|
||||
|
||||
my $hc_started = time; # count from time lock is granted
|
||||
|
||||
if ( $opt{dryrun} ) {
|
||||
print "LOCK TABLES $hc_locks\n";
|
||||
print "FLUSH TABLES\n";
|
||||
print "FLUSH LOGS\n" if ( $opt{flushlog} );
|
||||
}
|
||||
else {
|
||||
my $start = time;
|
||||
$dbh->do("LOCK TABLES $hc_locks");
|
||||
printf "Locked $num_tables tables in %d seconds.\n", time-$start unless $opt{quiet};
|
||||
$hc_started = time; # count from time lock is granted
|
||||
|
||||
# flush tables to make on-disk copy uptodate
|
||||
$start = time;
|
||||
$dbh->do("FLUSH TABLES");
|
||||
printf "Flushed tables in %d seconds.\n", time-$start unless $opt{quiet};
|
||||
$dbh->do( "FLUSH LOGS" ) if ( $opt{flushlog} );
|
||||
}
|
||||
|
||||
my @failed = ();
|
||||
|
||||
foreach my $rdb ( @db_desc ) {
|
||||
my @files = map { "$datadir/$rdb->{src}/$_" } @{$rdb->{files}};
|
||||
next unless @files;
|
||||
eval { copy_files($opt{method}, \@files, $rdb->{target} ); };
|
||||
|
||||
push @failed, "$rdb->{src} -> $rdb->{target} failed: $@"
|
||||
if ( $@ );
|
||||
|
||||
if ( $opt{checkpoint} ) {
|
||||
my $msg = ( $@ ) ? "Failed: $@" : "Succeeded";
|
||||
|
||||
eval {
|
||||
$dbh->do( qq{ insert into $opt{checkpoint} (src, dest, msg)
|
||||
VALUES ( '$rdb->{src}', '$rdb->{target}', '$msg' )
|
||||
} );
|
||||
};
|
||||
|
||||
if ( $@ ) {
|
||||
warn "Failed to update checkpoint table: $@\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $opt{dryrun} ) {
|
||||
print "UNLOCK TABLES\n";
|
||||
if ( @existing && !$opt{keepold} ) {
|
||||
my @oldies = map { $_ . '_old' } @existing;
|
||||
print "rm -rf @oldies\n"
|
||||
}
|
||||
$dbh->disconnect();
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
$dbh->do("UNLOCK TABLES");
|
||||
}
|
||||
|
||||
my $hc_dur = time - $hc_started;
|
||||
printf "Unlocked tables.\n" unless $opt{quiet};
|
||||
|
||||
#
|
||||
# --- HOT-COPY COMPLETE ---
|
||||
###########################
|
||||
|
||||
$dbh->disconnect;
|
||||
|
||||
if ( @failed ) {
|
||||
# hotcopy failed - cleanup
|
||||
# delete any @targets
|
||||
# rename _old copy back to original
|
||||
|
||||
print "Deleting @targets \n" if $opt{debug};
|
||||
rmtree([@targets]);
|
||||
if (@existing) {
|
||||
print "Restoring @existing from back-up\n" if $opt{debug};
|
||||
foreach my $dir ( @existing ) {
|
||||
rename("${dir}_old", $dir )
|
||||
or warn "Can't rename ${dir}_old to $dir: $!\n";
|
||||
}
|
||||
}
|
||||
|
||||
die join( "\n", @failed );
|
||||
}
|
||||
else {
|
||||
# hotcopy worked
|
||||
# delete _old unless $opt{keepold}
|
||||
|
||||
if ( @existing && !$opt{keepold} ) {
|
||||
my @oldies = map { $_ . '_old' } @existing;
|
||||
print "Deleting previous copy in @oldies\n" if $opt{debug};
|
||||
rmtree([@oldies]);
|
||||
}
|
||||
|
||||
printf "$0 copied %d tables (%d files) in %d second%s (%d seconds overall).\n",
|
||||
$num_tables, $num_files,
|
||||
$hc_dur, ($hc_dur==1)?"":"s", time - $start_time
|
||||
unless $opt{quiet};
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
|
||||
# ---
|
||||
|
||||
sub copy_files {
|
||||
my ($method, $files, $target) = @_;
|
||||
my @cmd;
|
||||
print "Copying ".@$files." files...\n" unless $opt{quiet};
|
||||
if ($method =~ /^s?cp\b/) { # cp or scp with optional flags
|
||||
@cmd = ($method);
|
||||
# add option to preserve mod time etc of copied files
|
||||
# not critical, but nice to have
|
||||
push @cmd, "-p" if $^O =~ m/^(solaris|linux)$/;
|
||||
# add files to copy and the destination directory
|
||||
push @cmd, @$files, $target;
|
||||
}
|
||||
else {
|
||||
die "Can't use unsupported method '$method'\n";
|
||||
}
|
||||
|
||||
if ( $opt{dryrun} ) {
|
||||
print "@cmd\n";
|
||||
next;
|
||||
}
|
||||
|
||||
print "Executing '@cmd'\n" if $opt{debug};
|
||||
my $cp_status = system @cmd;
|
||||
if ($cp_status != 0) {
|
||||
die "Error: @cmd failed ($cp_status) while copying files.\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub retire_directory {
|
||||
my ( @dir ) = @_;
|
||||
|
||||
foreach my $dir ( @dir ) {
|
||||
my $tgt_oldpath = $dir . '_old';
|
||||
if ( $opt{dryrun} ) {
|
||||
print "rmtree $tgt_oldpath\n" if ( -d $tgt_oldpath );
|
||||
print "rename $dir, $tgt_oldpath\n";
|
||||
next;
|
||||
}
|
||||
|
||||
if ( -d $tgt_oldpath ) {
|
||||
print "Deleting previous 'old' hotcopy directory ('$tgt_oldpath')\n" unless $opt{quiet};
|
||||
rmtree([$tgt_oldpath])
|
||||
}
|
||||
rename($dir, $tgt_oldpath)
|
||||
or die "Can't rename $dir=>$tgt_oldpath: $!\n";
|
||||
print "Existing hotcopy directory renamed to '$tgt_oldpath'\n" unless $opt{quiet};
|
||||
}
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
mysqlhotcopy is designed to make stable copies of live MySQL databases.
|
||||
|
||||
Here "live" means that the database server is running and the database
|
||||
may be in active use. And "stable" means that the copy will not have
|
||||
any corruptions that could occur if the table files were simply copied
|
||||
without first being locked and flushed from within the server.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 4
|
||||
|
||||
=item --checkpoint checkpoint-table
|
||||
|
||||
As each database is copied, an entry is written to the specified
|
||||
checkpoint-table. This has the happy side-effect of updating the
|
||||
MySQL update-log (if it is switched on) giving a good indication of
|
||||
where roll-forward should begin for backup+rollforward schemes.
|
||||
|
||||
The name of the checkpoint table should be supplied in database.table format.
|
||||
The checkpoint-table must contain at least the following fields:
|
||||
|
||||
=over 4
|
||||
|
||||
time_stamp timestamp not null
|
||||
src varchar(32)
|
||||
dest varchar(60)
|
||||
msg varchar(255)
|
||||
|
||||
=back
|
||||
|
||||
=item --suffix suffix
|
||||
|
||||
Each database is copied back into the originating datadir under
|
||||
a new name. The new name is the original name with the suffix
|
||||
appended.
|
||||
|
||||
If only a single db_name is supplied and the --suffix flag is not
|
||||
supplied, then "--suffix=_copy" is assumed.
|
||||
|
||||
=item --allowold
|
||||
|
||||
Move any existing version of the destination to a backup directory for
|
||||
the duration of the copy. If the copy successfully completes, the backup
|
||||
directory is deleted - unless the --keepold flag is set. If the copy fails,
|
||||
the backup directory is restored.
|
||||
|
||||
The backup directory name is the original name with "_old" appended.
|
||||
Any existing versions of the backup directory are deleted.
|
||||
|
||||
=item --keepold
|
||||
|
||||
Behaves as for the --allowold, with the additional feature
|
||||
of keeping the backup directory after the copy successfully completes.
|
||||
|
||||
=item --flushlog
|
||||
|
||||
Rotate the log files by executing "FLUSH LOGS" after all tables are
|
||||
locked, and before they are copied.
|
||||
|
||||
=item --regexp pattern
|
||||
|
||||
Copy all databases with names matching the pattern.
|
||||
|
||||
=item -?, --help
|
||||
|
||||
Display helpscreen and exit
|
||||
|
||||
=item -u, --user=#
|
||||
|
||||
user for database login if not current user
|
||||
|
||||
=item -p, --password=#
|
||||
|
||||
password to use when connecting to server
|
||||
|
||||
=item -P, --port=#
|
||||
|
||||
port to use when connecting to local server
|
||||
|
||||
=item -S, --socket=#
|
||||
|
||||
UNIX domain socket to use when connecting to local server
|
||||
|
||||
=item --noindices
|
||||
|
||||
don't copy index files
|
||||
|
||||
=item --method=#
|
||||
|
||||
method for copy (only "cp" currently supported)
|
||||
|
||||
=item -q, --quiet
|
||||
|
||||
be silent except for errors
|
||||
|
||||
=item --debug
|
||||
|
||||
Debug messages are displayed
|
||||
|
||||
=item -n, --dryrun
|
||||
|
||||
Display commands without actually doing them
|
||||
|
||||
=back
|
||||
|
||||
=head1 WARRANTY
|
||||
|
||||
This software is free and comes without warranty of any kind. You
|
||||
should never trust backup software without studying the code yourself.
|
||||
Study the code inside this script and only rely on it if I<you> believe
|
||||
that it does the right thing for you.
|
||||
|
||||
Patches adding bug fixes, documentation and new features are welcome.
|
||||
|
||||
=head1 TO DO
|
||||
|
||||
Allow a list of tables (or regex) to be given on the command line to
|
||||
enable a logically-related subset of the tables to be hot-copied
|
||||
rather than force the whole db to be copied in one go.
|
||||
|
||||
Extend the above to allow multiple subsets of tables to be specified
|
||||
on the command line:
|
||||
|
||||
mysqlhotcopy db newdb t1 t2 /^foo_/ : t3 /^bar_/ : +
|
||||
|
||||
where ":" delimits the subsets, the /^foo_/ indicates all tables
|
||||
with names begining with "foo_" and the "+" indicates all tables
|
||||
not copied by the previous subsets.
|
||||
|
||||
Add option to lock each table in turn for people who don't need
|
||||
cross-table integrity.
|
||||
|
||||
Add option to FLUSH STATUS just before UNLOCK TABLES.
|
||||
|
||||
Add support for other copy methods (eg tar to single file?).
|
||||
|
||||
Add support for forthcoming MySQL ``RAID'' table subdirectory layouts.
|
||||
|
||||
Add option to only copy the first 65KB of index files. That simplifies
|
||||
recovery (recovery with no index file at all is complicated).
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Tim Bunce
|
||||
|
||||
Martin Waite - added checkpoint, flushlog, regexp and dryrun options
|
||||
|
||||
Ralph Corderoy - Added synonyms for commands
|
||||
=cut
|
149
scripts/safe_mysqld-watch.sh
Executable file
149
scripts/safe_mysqld-watch.sh
Executable file
@@ -0,0 +1,149 @@
|
||||
#!/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
|
||||
#
|
||||
# scripts to start the MySQL demon and restart it if it dies unexpectedly
|
||||
#
|
||||
# This should be executed in the MySQL base directory if you are using a
|
||||
# binary installation that has other paths than you are using.
|
||||
#
|
||||
# mysql.server works by first doing a cd to the base directory and from there
|
||||
# executing safe_mysqld
|
||||
|
||||
# Check if we are starting this relative (for the binary release)
|
||||
if test -f ./data/mysql/db.frm -a -f ./share/mysql/english/errmsg.sys -a \
|
||||
-x ./bin/mysqld
|
||||
then
|
||||
MY_BASEDIR_VERSION=`pwd` # Where bin, share and data is
|
||||
DATADIR=$MY_BASEDIR_VERSION/data # Where the databases are
|
||||
ledir=$MY_BASEDIR_VERSION/bin # Where mysqld are
|
||||
# Check if this is a 'moved install directory'
|
||||
elif test -f ./var/mysql/db.frm -a -f ./share/mysql/english/errmsg.sys -a \
|
||||
-x ./libexec/mysqld
|
||||
then
|
||||
MY_BASEDIR_VERSION=`pwd` # Where libexec, share and var is
|
||||
DATADIR=$MY_BASEDIR_VERSION/var # Where the databases are
|
||||
ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld are
|
||||
else
|
||||
MY_BASEDIR_VERSION=/usr/local/mysql
|
||||
DATADIR=/usr/local/mysql/var
|
||||
ledir=/usr/local/mysql/libexec
|
||||
fi
|
||||
|
||||
pidfile=$DATADIR/`/bin/hostname`.pid
|
||||
log=$DATADIR/`/bin/hostname`.log
|
||||
err=$DATADIR/`/bin/hostname`.err
|
||||
lockfile=$DATADIR/`/bin/hostname`.lock
|
||||
|
||||
#
|
||||
# If there exists an old pid file, check if the demon is already running
|
||||
# Note: The switches to 'ps' may depend on your operating system
|
||||
|
||||
if test -f $pidfile
|
||||
then
|
||||
PID=`cat $pidfile`
|
||||
if /bin/kill -0 $PID
|
||||
then
|
||||
if /bin/ps -p $PID | grep mysqld > /dev/null
|
||||
then # The pid contains a mysqld process
|
||||
echo "A mysqld process already exists"
|
||||
echo "A mysqld process already exists at " `date` >> $log
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
rm -f $pidfile
|
||||
if test -f $pidfile
|
||||
then
|
||||
echo "Fatal error: Can't remove the pid file: $pidfile"
|
||||
echo "Fatal error: Can't remove the pid file: $pidfile at " `date` >> $log
|
||||
echo "Please remove it manually and start $0 again"
|
||||
echo "mysqld demon not started"
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Starting mysqld demon with databases from $DATADIR"
|
||||
|
||||
#Default communication ports
|
||||
#MYSQL_TCP_PORT=3306
|
||||
if test -z "$MYSQL_UNIX_PORT"
|
||||
then
|
||||
MYSQL_UNIX_PORT="/tmp/mysql.sock"
|
||||
export MYSQL_UNIX_PORT
|
||||
fi
|
||||
#export MYSQL_TCP_PORT
|
||||
|
||||
# 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
|
||||
|
||||
echo "mysqld started on " `date` >> $log
|
||||
bin/zap -f $lockfile < /dev/null > /dev/null 2>&1
|
||||
rm -f $lockfile
|
||||
$MY_BASEDIR_VERSION/bin/watchdog_mysqld $lockfile $pidfile $MY_BASEDIR_VERSION/bin $DATADIR 3 10 >> $err 2>&1 &
|
||||
restart_pid=$!
|
||||
|
||||
while true
|
||||
do
|
||||
rm -f $MYSQL_UNIX_PORT $pidfile # Some extra safety
|
||||
lockfile -1 -r10 $lockfile >/dev/null 2>&1
|
||||
if test "$#" -eq 0
|
||||
then
|
||||
nohup $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR \
|
||||
--skip-locking >> $err 2>&1 &
|
||||
else
|
||||
nohup $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR \
|
||||
--skip-locking "$@" >> $err 2>&1 &
|
||||
fi
|
||||
pid=$!
|
||||
rm -f $lockfile
|
||||
wait $pid;
|
||||
|
||||
lockfile -1 -r10 $lockfile >/dev/null 2>&1
|
||||
rm -f $lockfile
|
||||
if test ! -f $pidfile # This is removed if normal shutdown
|
||||
then
|
||||
break;
|
||||
fi
|
||||
if true
|
||||
then
|
||||
# Test if one proces 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 proces won't react on the kill.
|
||||
numofproces=`ps x | grep -v "grep" | grep -c $ledir/mysqld`
|
||||
echo -e "\nNumber of processes running now: $numofproces" | tee -a $log
|
||||
I=1
|
||||
while test "$I" -le "$numofproces"
|
||||
do
|
||||
PROC=`ps x | grep $ledir/mysqld | grep -v "grep" | tail -1`
|
||||
for T in $PROC
|
||||
do
|
||||
break
|
||||
done
|
||||
# echo "TEST $I - $T **"
|
||||
if kill -9 $T
|
||||
then
|
||||
echo "mysqld proces hanging, pid $T - killed" | tee -a $log
|
||||
else
|
||||
break
|
||||
fi
|
||||
I=`expr $I + 1`
|
||||
done
|
||||
fi
|
||||
echo "mysqld restarted" | tee -a $log
|
||||
# Check all tables and repair any wrong tables.
|
||||
$MY_BASEDIR_VERSION/bin/isamchk -sf $DATADIR/*/*.ISM >> $err 2>&1
|
||||
done
|
||||
if test $restart_pid -gt 0
|
||||
then
|
||||
kill $restart_pid > /dev/null 2>&1
|
||||
sleep 1;
|
||||
kill -9 $restart_pid > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
echo -n "mysqld ended on " `date` >> $log
|
||||
echo "mysqld demon ended"
|
188
scripts/safe_mysqld.sh
Executable file
188
scripts/safe_mysqld.sh
Executable file
@@ -0,0 +1,188 @@
|
||||
#!/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
|
||||
#
|
||||
# scripts 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 has other paths than you are using.
|
||||
#
|
||||
# mysql.server works by first doing a cd to the base directory and from there
|
||||
# executing safe_mysqld
|
||||
|
||||
trap '' 1 2 3 15 # we shouldn't let anyone kill us
|
||||
|
||||
defaults=
|
||||
case "$1" in
|
||||
--no-defaults|--defaults-file=*)
|
||||
defaults="$1"; shift
|
||||
;;
|
||||
esac
|
||||
|
||||
# Parse arguments to see if caller wants the pid_file somewhere else.
|
||||
parse_arguments() {
|
||||
for arg; do
|
||||
case $arg in
|
||||
--datadir=*) DATADIR=`echo "$arg" | sed -e "s;--datadir=;;"` ;;
|
||||
--pid-file=*) pid_file=`echo "$arg" | sed -e "s;--pid-file=;;"` ;;
|
||||
--socket=*) MYSQL_UNIX_PORT=`echo "$arg" | sed -e "s;--socket=;;"` ;;
|
||||
--log=*) log=`echo "$arg" | sed -e "s;--log=;;"` ;;
|
||||
--err-log=*) err_log=`echo "$arg" | sed -e "s;--err-log=;;"` ;;
|
||||
--basedir=*) MY_BASEDIR_VERSION=`echo "$arg" | sed -e "s;--basedir=;;"` ;;
|
||||
--ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;;
|
||||
--user=*) user=`echo "$arg" | sed -e "s;--user=;;"` ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
MY_PWD=`pwd`
|
||||
# Check if we are starting this relative (for the binary release)
|
||||
if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
|
||||
-x ./bin/mysqld
|
||||
then
|
||||
MY_BASEDIR_VERSION=$MY_PWD # Where bin, share and data are
|
||||
ledir=$MY_BASEDIR_VERSION/bin # Where mysqld is
|
||||
DATADIR=$MY_BASEDIR_VERSION/data
|
||||
# Check if this is a 'moved install directory'
|
||||
elif test -f ./var/mysql/db.frm -a -f ./share/mysql/english/errmsg.sys -a \
|
||||
-x ./libexec/mysqld
|
||||
then
|
||||
MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
|
||||
ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld is
|
||||
DATADIR=$MY_BASEDIR_VERSION/var
|
||||
else
|
||||
MY_BASEDIR_VERSION=@prefix@
|
||||
DATADIR=@localstatedir@
|
||||
ledir=@libexecdir@
|
||||
fi
|
||||
|
||||
pid_file=$DATADIR/`/bin/hostname`.pid
|
||||
MYSQL_UNIX_PORT=@MYSQL_UNIX_ADDR@
|
||||
MYSQL_TCP_PORT=@MYSQL_TCP_PORT@
|
||||
log=$DATADIR/`/bin/hostname`.log
|
||||
err_log=$DATADIR/`/bin/hostname`.err
|
||||
user=@MYSQLD_USER@
|
||||
|
||||
# Get first arguments from the my.cfg file, groups [mysqld] and [safe_mysqld]
|
||||
# and then merge with the command line arguments
|
||||
if test -x ./bin/my_print_defaults; then
|
||||
print_defaults="./bin/my_print_defaults"
|
||||
elif test -x @bindir@/my_print_defaults; then
|
||||
print_defaults="@bindir@/my_print_defaults"
|
||||
elif test -x @bindir@/mysql_print_defaults; then
|
||||
print_defaults="@bindir@/mysql_print_defaults"
|
||||
else
|
||||
print_defaults="my_print_defaults"
|
||||
fi
|
||||
parse_arguments `$print_defaults $defaults mysqld safe_mysqld`
|
||||
parse_arguments "$@"
|
||||
|
||||
if test ! -x $ledir/mysqld
|
||||
then
|
||||
echo "The file $ledir/mysqld doesn't exist or is not executable"
|
||||
echo "Please do a cd to the mysql installation directory and restart"
|
||||
echo "this script from there as follows:"
|
||||
echo "./bin/safe_mysqld".
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
NOHUP_NICENESS=`nohup nice`
|
||||
if [ "x$NOHUP_NICENESS" = "x0" ] || ! nice --1 nice >/dev/null 2>&1 ; then
|
||||
NOHUP_NICENESS="nohup"
|
||||
else
|
||||
NOHUP_NICENESS="nice --$NOHUP_NICENESS nohup"
|
||||
fi
|
||||
|
||||
|
||||
export MYSQL_UNIX_PORT
|
||||
#export MYSQL_TCP_PORT
|
||||
touch $err_log; chown $user $err_log
|
||||
|
||||
#
|
||||
# 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 @CHECK_PID@
|
||||
then
|
||||
if @FIND_PROC@
|
||||
then # The pid contains a mysqld process
|
||||
echo "A mysqld process already exists"
|
||||
echo "A mysqld process already exists at " `date` >> $err_log
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
rm -f $pid_file
|
||||
if test -f $pid_file
|
||||
then
|
||||
echo "Fatal error: Can't remove the pid file: $pid_file"
|
||||
echo "Fatal error: Can't remove the pid file: $pid_file at " `date` >> $err_log
|
||||
echo "Please remove it manually and start $0 again"
|
||||
echo "mysqld daemon not started"
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Uncomment the following lines if you want all tables to be automaticly
|
||||
# checked and repaired at start
|
||||
#
|
||||
# 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
|
||||
|
||||
echo "Starting mysqld daemon with databases from $DATADIR"
|
||||
|
||||
# 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
|
||||
|
||||
echo "`date +'%y%m%d %H:%M:%S mysqld started'`" >> $err_log
|
||||
while true
|
||||
do
|
||||
rm -f $MYSQL_UNIX_PORT $pid_file # Some extra safety
|
||||
if test "$#" -eq 0
|
||||
then
|
||||
(trap "" 1 ; exec $NOHUP_NICENESS $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR --user=$user --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ >> $err_log 2>&1 )
|
||||
else
|
||||
(trap "" ; exec $NOHUP_NICENESS $ledir/mysqld --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR --user=$user --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ "$@" >> $err_log 2>&1 )
|
||||
fi
|
||||
if test ! -f $pid_file # This is removed if normal shutdown
|
||||
then
|
||||
break;
|
||||
fi
|
||||
if @IS_LINUX@
|
||||
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 xa | grep -v "grep" | grep -c $ledir/mysqld`
|
||||
echo -e "\nNumber of processes running now: $numofproces" | tee -a $err_log
|
||||
I=1
|
||||
while test "$I" -le "$numofproces"
|
||||
do
|
||||
PROC=`ps xa | grep $ledir/mysqld | grep -v "grep" | tail -1`
|
||||
for T in $PROC
|
||||
do
|
||||
break
|
||||
done
|
||||
# echo "TEST $I - $T **"
|
||||
if kill -9 $T
|
||||
then
|
||||
echo "mysqld process hanging, pid $T - killed" | tee -a $err_log
|
||||
else
|
||||
break
|
||||
fi
|
||||
I=`expr $I + 1`
|
||||
done
|
||||
fi
|
||||
echo "`date +'%y%m%d %H:%M:%S mysqld restarted'`" | tee -a $err_log
|
||||
done
|
||||
|
||||
echo -e "`date +'%y%m%d %H:%M:%S mysqld ended\n'`" | tee -a $err_log
|
Reference in New Issue
Block a user