2000-07-31 21:29:14 +02:00
|
|
|
#!/bin/sh
|
2003-06-04 17:28:51 +02:00
|
|
|
# This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
|
|
|
|
# through the mysql client program to the mysqld server
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
# Default values (Can be changed in my.cnf)
|
|
|
|
password=""
|
2000-07-31 21:29:14 +02:00
|
|
|
host="localhost"
|
2002-12-23 14:36:40 +01:00
|
|
|
user="root"
|
2003-06-04 17:28:51 +02:00
|
|
|
sql_only=0
|
2004-07-15 03:19:07 +02:00
|
|
|
basedir="@prefix@"
|
2003-06-04 17:28:51 +02:00
|
|
|
verbose=0
|
|
|
|
args=""
|
2004-03-10 19:54:07 +01:00
|
|
|
port=""
|
|
|
|
socket=""
|
|
|
|
database="mysql"
|
2005-03-22 14:48:06 +01:00
|
|
|
bindir=""
|
2004-07-15 03:19:07 +02:00
|
|
|
pkgdatadir="@pkgdatadir@"
|
2004-12-09 11:47:20 +01:00
|
|
|
print_defaults_bindir="."
|
2003-06-04 17:28:51 +02:00
|
|
|
|
|
|
|
file=mysql_fix_privilege_tables.sql
|
|
|
|
|
2004-07-06 16:29:26 +02:00
|
|
|
# The following test is to make this script compatible with the 4.0 where
|
|
|
|
# the single argument could be a password
|
|
|
|
if test "$#" = 1
|
|
|
|
then
|
|
|
|
case "$1" in
|
|
|
|
--*) ;;
|
|
|
|
*) old_style_password="$1" ; shift ;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
# The following code is almost identical to the code in mysql_install_db.sh
|
|
|
|
|
2004-07-06 16:29:26 +02:00
|
|
|
case "$1" in
|
|
|
|
--no-defaults|--defaults-file=*|--defaults-extra-file=*)
|
|
|
|
defaults="$1"; shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
parse_arguments() {
|
|
|
|
# We only need to pass arguments through to the server if we don't
|
|
|
|
# handle them here. So, we collect unrecognized options (passed on
|
|
|
|
# the command line) into the args variable.
|
|
|
|
pick_args=
|
|
|
|
if test "$1" = PICK-ARGS-FROM-ARGV
|
|
|
|
then
|
|
|
|
pick_args=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
for arg do
|
|
|
|
case "$arg" in
|
|
|
|
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
|
|
|
|
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
|
|
|
|
--password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
|
|
|
|
--host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
|
2004-07-06 16:29:26 +02:00
|
|
|
--sql|--sql-only) sql_only=1 ;;
|
2003-06-04 17:28:51 +02:00
|
|
|
--verbose) verbose=1 ;;
|
2004-03-10 19:54:07 +01:00
|
|
|
--port=*) port=`echo "$arg" | sed -e "s;--port=;;"` ;;
|
|
|
|
--socket=*) socket=`echo "$arg" | sed -e "s;--socket=;;"` ;;
|
|
|
|
--database=*) database=`echo "$arg" | sed -e "s;--database=;;"` ;;
|
2004-12-09 11:47:20 +01:00
|
|
|
--bindir=*) bindir=`echo "$arg" | sed -e "s;--bindir=;;"`
|
|
|
|
print_defaults_bindir=$bindir
|
|
|
|
;;
|
2003-06-04 17:28:51 +02:00
|
|
|
*)
|
|
|
|
if test -n "$pick_args"
|
|
|
|
then
|
|
|
|
# This sed command makes sure that any special chars are quoted,
|
|
|
|
# so the arg gets passed exactly to the server.
|
2004-07-06 16:29:26 +02:00
|
|
|
args="$args "`echo "$arg" | sed -e 's,\([^=a-zA-Z0-9_.-]\),\\\\\1,g'`
|
2003-06-04 17:28:51 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get first arguments from the my.cfg file, groups [mysqld] and
|
|
|
|
# [mysql_install_db], and then merge with the command line arguments
|
2004-03-19 17:33:38 +01:00
|
|
|
|
2004-12-06 01:00:37 +01:00
|
|
|
print_defaults=my_print_defaults
|
2004-12-09 11:47:20 +01:00
|
|
|
for dir in ./bin @bindir@ @bindir@ extra $print_defaults_bindir/../bin $print_defaults_bindir/../extra
|
2004-03-19 17:33:38 +01:00
|
|
|
do
|
|
|
|
if test -x $dir/my_print_defaults
|
|
|
|
then
|
|
|
|
print_defaults="$dir/my_print_defaults"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
|
|
|
|
parse_arguments PICK-ARGS-FROM-ARGV "$@"
|
2003-04-09 21:19:53 +02:00
|
|
|
|
2004-07-15 03:19:07 +02:00
|
|
|
if test -z "$password"
|
2000-07-31 21:29:14 +02:00
|
|
|
then
|
2004-07-15 03:19:07 +02:00
|
|
|
password=$old_style_password
|
2000-07-31 21:29:14 +02:00
|
|
|
fi
|
|
|
|
|
2004-07-15 03:19:07 +02:00
|
|
|
# Find where 'mysql' command is located
|
|
|
|
|
2005-10-04 23:08:22 +02:00
|
|
|
dirname=`dirname "$0"`
|
|
|
|
|
2004-07-15 03:19:07 +02:00
|
|
|
if test -z "$bindir"
|
2002-06-12 14:04:18 +02:00
|
|
|
then
|
2005-10-04 23:08:22 +02:00
|
|
|
for i in @bindir@ $basedir/bin "$dirname/../client"
|
2004-07-15 03:19:07 +02:00
|
|
|
do
|
|
|
|
if test -f $i/mysql
|
|
|
|
then
|
|
|
|
bindir=$i
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2002-06-12 14:04:18 +02:00
|
|
|
fi
|
|
|
|
|
2005-10-04 23:08:22 +02:00
|
|
|
if test -z "$bindir"
|
|
|
|
then
|
|
|
|
echo "Could not find MySQL command-line client (mysql)."
|
|
|
|
echo "Please use --basedir to specify the directory where MySQL is installed."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2004-11-28 18:19:01 +01:00
|
|
|
cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host"
|
2004-06-28 15:37:42 +02:00
|
|
|
if test ! -z "$password" ; then
|
2004-03-16 21:41:30 +01:00
|
|
|
cmd="$cmd --password=$password"
|
2003-06-04 17:28:51 +02:00
|
|
|
fi
|
2004-03-16 21:41:30 +01:00
|
|
|
if test ! -z "$port"; then
|
|
|
|
cmd="$cmd --port=$port"
|
|
|
|
fi
|
|
|
|
if test ! -z "$socket"; then
|
|
|
|
cmd="$cmd --socket=$socket"
|
|
|
|
fi
|
|
|
|
cmd="$cmd --database=$database"
|
2002-06-12 14:04:18 +02:00
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
if test $sql_only = 1
|
|
|
|
then
|
|
|
|
cmd="cat"
|
|
|
|
fi
|
2002-11-30 18:58:53 +01:00
|
|
|
|
2004-06-25 12:26:50 +02:00
|
|
|
# Find where first mysql_fix_privilege_tables.sql is located
|
2003-06-04 17:28:51 +02:00
|
|
|
for i in $basedir/support-files $basedir/share $basedir/share/mysql \
|
2005-10-04 23:08:22 +02:00
|
|
|
$basedir/scripts $pkgdatadir . "$dirname"
|
2003-06-04 17:28:51 +02:00
|
|
|
do
|
|
|
|
if test -f $i/$file
|
|
|
|
then
|
|
|
|
pkgdatadir=$i
|
2004-06-25 12:09:26 +02:00
|
|
|
break
|
2003-06-04 17:28:51 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
sql_file="$pkgdatadir/$file"
|
|
|
|
if test ! -f $sql_file
|
|
|
|
then
|
|
|
|
echo "Could not find file '$file'."
|
|
|
|
echo "Please use --basedir to specify the directory where MySQL is installed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2002-11-30 18:58:53 +01:00
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
s_echo()
|
|
|
|
{
|
|
|
|
if test $sql_only = 0
|
|
|
|
then
|
|
|
|
echo $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2004-07-14 18:33:00 +02:00
|
|
|
s_echo "This script updates all the mysql privilege tables to be usable by"
|
2006-02-24 00:29:50 +01:00
|
|
|
s_echo "MySQL 5.1 and above."
|
2003-06-04 17:28:51 +02:00
|
|
|
s_echo ""
|
|
|
|
|
|
|
|
if test $verbose = 1
|
|
|
|
then
|
|
|
|
s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
|
2004-06-28 18:26:54 +02:00
|
|
|
s_echo "because these just mean that your tables are already up to date."
|
2003-06-04 17:28:51 +02:00
|
|
|
s_echo "This script is safe to run even if your tables are already up to date!"
|
|
|
|
s_echo ""
|
|
|
|
fi
|
2002-09-16 14:55:19 +02:00
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
if test $verbose = 0
|
|
|
|
then
|
|
|
|
cat $sql_file | $cmd > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
cat $sql_file | $cmd > /dev/null
|
|
|
|
fi
|
|
|
|
if test $? = 0
|
|
|
|
then
|
|
|
|
s_echo "done"
|
|
|
|
else
|
|
|
|
s_echo "Got a failure from command:"
|
2004-11-03 11:39:38 +01:00
|
|
|
s_echo "cat $sql_file | $cmd"
|
2003-06-04 17:28:51 +02:00
|
|
|
s_echo "Please check the above output and try again."
|
|
|
|
if test $verbose = 0
|
|
|
|
then
|
|
|
|
s_echo ""
|
|
|
|
s_echo "Running the script with the --verbose option may give you some information"
|
|
|
|
s_echo "of what went wrong."
|
|
|
|
fi
|
|
|
|
s_echo ""
|
|
|
|
s_echo "If you get an 'Access denied' error, you should run this script again and"
|
|
|
|
s_echo "give the MySQL root user password as an argument with the --password= option"
|
|
|
|
fi
|