2
# Copyright (C) 2000-2006 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
18
# through the mysql client program to the mysqld server
20
# Default values (Can be changed in my.cnf)
28
# no elaborate fallback here; with no argument, it will happen in "mysql"
33
pkgdatadir="@pkgdatadir@"
34
print_defaults_bindir="."
36
file=mysql_fix_privilege_tables.sql
38
# The following test is to make this script compatible with the 4.0 where
39
# the single argument could be a password
44
*) old_style_password="$1" ; shift ;;
48
# The following code is almost identical to the code in mysql_install_db.sh
51
--no-defaults|--defaults-file=*|--defaults-extra-file=*)
57
# We only need to pass arguments through to the server if we don't
58
# handle them here. So, we collect unrecognized options (passed on
59
# the command line) into the args variable.
61
if test "$1" = PICK-ARGS-FROM-ARGV
69
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
70
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
71
--password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
72
--host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
73
--sql|--sql-only) sql_only=1 ;;
74
--verbose) verbose=1 ;;
75
--port=*) port=`echo "$arg" | sed -e "s;--port=;;"` ;;
76
--socket=*) socket=`echo "$arg" | sed -e "s;--socket=;;"` ;;
77
--database=*) database=`echo "$arg" | sed -e "s;--database=;;"` ;;
78
--bindir=*) bindir=`echo "$arg" | sed -e "s;--bindir=;;"`
79
print_defaults_bindir=$bindir
82
if test -n "$pick_args"
84
# This sed command makes sure that any special chars are quoted,
85
# so the arg gets passed exactly to the server.
86
args="$args "`echo "$arg" | sed -e 's,\([^=a-zA-Z0-9_.-]\),\\\\\1,g'`
93
# Get first arguments from the my.cfg file, groups [mysqld] and
94
# [mysql_install_db], and then merge with the command line arguments
96
print_defaults=my_print_defaults
97
for dir in ./bin @bindir@ @bindir@ extra $print_defaults_bindir/../bin $print_defaults_bindir/../extra
99
if test -x $dir/my_print_defaults
101
print_defaults="$dir/my_print_defaults"
106
parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
107
parse_arguments PICK-ARGS-FROM-ARGV "$@"
109
if test -z "$password"
111
password=$old_style_password
114
# Find where 'mysql' command is located
116
dirname=`dirname "$0"`
120
for i in @bindir@ $basedir/bin "$dirname/../client"
132
echo "Could not find MySQL command-line client (mysql)."
133
echo "Please use --basedir to specify the directory where MySQL is installed."
137
cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host"
138
if test ! -z "$port"; then
139
cmd="$cmd --port=$port"
141
if test ! -z "$socket"; then
142
cmd="$cmd --socket=$socket"
144
cmd="$cmd --database=$database"
146
if test $sql_only = 1
151
# Find where first mysql_fix_privilege_tables.sql is located
152
for i in $basedir/support-files $basedir/share $basedir/share/mysql \
153
$basedir/scripts $pkgdatadir . "$dirname"
162
sql_file="$pkgdatadir/$file"
163
if test ! -f $sql_file
165
echo "Could not find file '$file'."
166
echo "Please use --basedir to specify the directory where MySQL is installed"
172
if test $sql_only = 0
178
s_echo "This script updates all the mysql privilege tables to be usable by"
179
s_echo "the current version of MySQL"
184
s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
185
s_echo "because these just mean that your tables are already up to date."
186
s_echo "This script is safe to run even if your tables are already up to date!"
191
# Password argument is added here to allow for spaces in password.
193
if test ! -z "$password"
195
cat $sql_file | $cmd --password="$password"
203
run_cmd > /dev/null 2>&1
211
s_echo "Got a failure from command:"
212
s_echo "cat $sql_file | $cmd"
213
s_echo "Please check the above output and try again."
217
s_echo "Running the script with the --verbose option may give you some information"
218
s_echo "of what went wrong."
221
s_echo "If you get an 'Access denied' error, you should run this script again and"
222
s_echo "give the MySQL root user password as an argument with the --password= option"