home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / mysql / scripts / mysql_fix_privilege_tables < prev    next >
Encoding:
Text File  |  2008-04-17  |  5.6 KB  |  223 lines

  1. #!/bin/sh
  2. # Copyright (C) 2000-2006 MySQL AB
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; version 2 of the License.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program; if not, write to the Free Software
  12. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  13.  
  14. # This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
  15. # through the mysql client program to the mysqld server
  16.  
  17. # Default values (Can be changed in my.cnf)
  18. password=""
  19. host="localhost"
  20. user="root"
  21. sql_only=0
  22. basedir="@prefix@"
  23. verbose=0
  24. args=""
  25. port=""
  26. socket=""
  27. database="mysql"
  28. bindir=""
  29. pkgdatadir="@pkgdatadir@"
  30. print_defaults_bindir="."
  31.  
  32. file=mysql_fix_privilege_tables.sql
  33.  
  34. # The following test is to make this script compatible with the 4.0 where
  35. # the single argument could be a password
  36. if test "$#" = 1
  37. then
  38.   case "$1" in
  39.   --*) ;;
  40.   *) old_style_password="$1" ; shift ;;
  41.   esac
  42. fi
  43.  
  44. # The following code is almost identical to the code in mysql_install_db.sh
  45.  
  46. case "$1" in
  47.     --no-defaults|--defaults-file=*|--defaults-extra-file=*)
  48.       defaults="$1"; shift
  49.       ;;
  50. esac
  51.  
  52. parse_arguments() {
  53.   # We only need to pass arguments through to the server if we don't
  54.   # handle them here.  So, we collect unrecognized options (passed on
  55.   # the command line) into the args variable.
  56.   pick_args=
  57.   if test "$1" = PICK-ARGS-FROM-ARGV
  58.   then
  59.     pick_args=1
  60.     shift
  61.   fi
  62.  
  63.   for arg do
  64.     case "$arg" in
  65.       --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  66.       --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  67.       --password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  68.       --host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  69.       --sql|--sql-only) sql_only=1 ;;
  70.       --verbose) verbose=1 ;;
  71.       --port=*) port=`echo "$arg" | sed -e "s;--port=;;"` ;;
  72.       --socket=*) socket=`echo "$arg" | sed -e "s;--socket=;;"` ;;
  73.       --database=*) database=`echo "$arg" | sed -e "s;--database=;;"` ;;
  74.       --bindir=*) bindir=`echo "$arg" | sed -e "s;--bindir=;;"`
  75.                   print_defaults_bindir=$bindir
  76.           ;;
  77.       *)
  78.         if test -n "$pick_args"
  79.         then
  80.           # This sed command makes sure that any special chars are quoted,
  81.           # so the arg gets passed exactly to the server.
  82.           args="$args "`echo "$arg" | sed -e 's,\([^=a-zA-Z0-9_.-]\),\\\\\1,g'`
  83.         fi
  84.         ;;
  85.     esac
  86.   done
  87. }
  88.  
  89. # Get first arguments from the my.cfg file, groups [mysqld] and
  90. # [mysql_install_db], and then merge with the command line arguments
  91.  
  92. print_defaults=my_print_defaults
  93. for dir in ./bin @bindir@ @bindir@ extra $print_defaults_bindir/../bin $print_defaults_bindir/../extra
  94. do
  95.   if test -x $dir/my_print_defaults
  96.   then
  97.     print_defaults="$dir/my_print_defaults"
  98.     break
  99.   fi
  100. done
  101.  
  102. parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
  103. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  104.  
  105. if test -z "$password"
  106. then
  107.   password=$old_style_password
  108. fi
  109.  
  110. # Find where 'mysql' command is located
  111.  
  112. dirname=`dirname "$0"`
  113.  
  114. if test -z "$bindir"
  115. then
  116.   for i in @bindir@ $basedir/bin "$dirname/../client"
  117.   do
  118.     if test -f $i/mysql
  119.     then
  120.       bindir=$i
  121.       break
  122.     fi
  123.   done
  124. fi
  125.  
  126. if test -z "$bindir"
  127. then
  128.   echo "Could not find MySQL command-line client (mysql)."
  129.   echo "Please use --basedir to specify the directory where MySQL is installed."
  130.   exit 1
  131. fi
  132.  
  133. cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host"
  134. if test ! -z "$port"; then
  135.   cmd="$cmd --port=$port"
  136. fi
  137. if test ! -z "$socket"; then
  138.   cmd="$cmd --socket=$socket"
  139. fi
  140. cmd="$cmd --database=$database"
  141.  
  142. if test $sql_only = 1
  143. then
  144.   cmd="cat"
  145. fi
  146.  
  147. # Find where first mysql_fix_privilege_tables.sql is located
  148. for i in $basedir/support-files $basedir/share $basedir/share/mysql \
  149.         $basedir/scripts $pkgdatadir . "$dirname"
  150. do
  151.   if test -f $i/$file
  152.   then
  153.     pkgdatadir=$i
  154.     break
  155.   fi
  156. done
  157.  
  158. sql_file="$pkgdatadir/$file"
  159. if test ! -f $sql_file
  160. then
  161.   echo "Could not find file '$file'."
  162.   echo "Please use --basedir to specify the directory where MySQL is installed"
  163.   exit 1
  164. fi
  165.  
  166. s_echo()
  167. {
  168.    if test $sql_only = 0
  169.    then
  170.      echo $1
  171.    fi
  172. }
  173.  
  174. s_echo "This script updates all the mysql privilege tables to be usable by"
  175. s_echo "the current version of MySQL"
  176. s_echo ""
  177.  
  178. if test $verbose = 1
  179. then
  180.   s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
  181.   s_echo "because these just mean that your tables are already up to date."
  182.   s_echo "This script is safe to run even if your tables are already up to date!"
  183.   s_echo ""
  184. fi
  185.  
  186. run_cmd() {
  187.   # Password argument is added here to allow for spaces in password.
  188.   
  189.   if test ! -z "$password"
  190.   then
  191.     cat $sql_file | $cmd --password="$password"
  192.   else
  193.     cat $sql_file | $cmd
  194.   fi
  195. }
  196.  
  197. if test $verbose = 0
  198. then
  199.   run_cmd > /dev/null 2>&1
  200. else
  201.   run_cmd > /dev/null
  202. fi
  203. if test $? = 0
  204. then
  205.   s_echo "done"
  206. else
  207.   s_echo "Got a failure from command:"
  208.   s_echo "cat $sql_file | $cmd"
  209.   s_echo "Please check the above output and try again."
  210.   if test $verbose = 0
  211.   then
  212.     s_echo ""
  213.     s_echo "Running the script with the --verbose option may give you some information"
  214.     s_echo "of what went wrong."
  215.   fi
  216.   s_echo ""
  217.   s_echo "If you get an 'Access denied' error, you should run this script again and"
  218.   s_echo "give the MySQL root user password as an argument with the --password= option"
  219. fi
  220.