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_upgrade_shell < prev    next >
Encoding:
Text File  |  2008-04-17  |  5.7 KB  |  216 lines

  1. #!/bin/sh
  2. # Copyright (C) 2002-2003 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. # Runs mysqlcheck --check-upgrade in case it has not been done on this
  15. # major MySQL version
  16.  
  17. # This script should always be run when upgrading from one major version
  18. # to another (ie: 4.1 -> 5.0 -> 5.1)
  19.  
  20. #
  21. # Note that in most cases one have to use '--password' as
  22. # arguments as these needs to be passed on to the mysqlcheck command
  23.  
  24.  
  25. user=root
  26.  
  27. case "$1" in
  28.     --no-defaults|--defaults-file=*|--defaults-extra-file=*)
  29.       defaults="$1"; shift
  30.       ;;
  31. esac
  32.  
  33. parse_arguments() {
  34.   # We only need to pass arguments through to the server if we don't
  35.   # handle them here.  So, we collect unrecognized options (passed on
  36.   # the command line) into the args variable.
  37.   pick_args=
  38.   if test "$1" = PICK-ARGS-FROM-ARGV
  39.   then
  40.     pick_args=1
  41.     shift
  42.   fi
  43.  
  44.   for arg do
  45.     case "$arg" in
  46.       --basedir=*) MY_BASEDIR_VERSION=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  47.       --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  48.       --ldata=*|--data=*|--datadir=*) DATADIR=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  49.       --force) force=1 ;;
  50.       --verbose) verbose=1 ;;
  51.       --help) help_option=1 ;;
  52.       *)
  53.         if test -n "$pick_args"
  54.         then
  55.           # This sed command makes sure that any special chars are quoted,
  56.           # so the arg gets passed exactly to the server.
  57.           args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.=-]\),\\\\\1,g'`
  58.         fi
  59.         ;;
  60.     esac
  61.   done
  62. }
  63.  
  64. #
  65. # Find where my_print_defaults is
  66. #
  67.  
  68. find_my_print_defaults () {
  69.   if test -x ./bin/my_print_defaults
  70.   then
  71.     print_defaults="./bin/my_print_defaults"
  72.   elif test -x ./extra/my_print_defaults
  73.   then
  74.     print_defaults="./extra/my_print_defaults"
  75.   elif test -x @bindir@/my_print_defaults
  76.   then
  77.     print_defaults="@bindir@/my_print_defaults"
  78.   elif test -x @bindir@/mysql_print_defaults
  79.   then
  80.     print_defaults="@bindir@/mysql_print_defaults"
  81.   else
  82.     print_defaults="my_print_defaults"
  83.   fi
  84. }
  85.  
  86. find_my_print_defaults
  87.  
  88. # Get first arguments from the my.cfg file, groups [mysqld] and
  89. # [mysql_upgrade], and then merge with the command line arguments
  90.  
  91. args=
  92. DATADIR=
  93. bindir=
  94. MY_BASEDIR_VERSION=
  95. verbose=0
  96. force=0
  97. help_option=0
  98.  
  99. parse_arguments `$print_defaults $defaults mysqld mysql_upgrade`
  100. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  101.  
  102. if test $help_option = 1
  103. then
  104.   echo "MySQL utility script to upgrade database to the current server version"
  105.   echo ""
  106.   echo "It takes the following arguments:"
  107.   echo "  --help     Show this help message"
  108.   echo "  --basedir  Specifies the directory where MySQL is installed"
  109.   echo "  --datadir  Specifies the data directory"
  110.   echo "  --force    Mysql_upgrade.info file will be ignored"
  111.   echo "  --user     Username for server login if not current user"
  112.   echo "  --verbose  Display more output about the process"
  113.   echo ""
  114.  
  115.   exit 0
  116. fi
  117.  
  118. #
  119. # Try to find where binaries are installed
  120. #
  121.  
  122. MY_PWD=`pwd`
  123. # Check for the directories we would expect from a binary release install
  124. if test -z "$MY_BASEDIR_VERSION"
  125. then
  126.   if test -f ./share/mysql/english/errmsg.sys -a -x ./bin/mysqld
  127.   then
  128.     MY_BASEDIR_VERSION=$MY_PWD            # Where bin, share and data are
  129.     bindir="$MY_BASEDIR_VERSION/bin"
  130.   # Check for the directories we would expect from a source install
  131.   elif test -f ./share/mysql/english/errmsg.sys -a -x ./libexec/mysqld
  132.   then
  133.     MY_BASEDIR_VERSION=$MY_PWD            # Where libexec, share and var are
  134.     bindir="$MY_BASEDIR_VERSION/bin"
  135. # Since we didn't find anything, used the compiled-in defaults
  136.   else
  137.     MY_BASEDIR_VERSION=@prefix@
  138.     bindir=@bindir@
  139.   fi
  140. else
  141.   bindir="$MY_BASEDIR_VERSION/bin"
  142. fi
  143.  
  144. #
  145. # Try to find the data directory
  146. #
  147.  
  148. if test -z "$DATADIR"
  149. then
  150.   # Try where the binary installs put it
  151.   if test -d $MY_BASEDIR_VERSION/data/mysql
  152.   then
  153.     DATADIR=$MY_BASEDIR_VERSION/data
  154.   # Next try where the source installs put it
  155.   elif test -d $MY_BASEDIR_VERSION/var/mysql
  156.   then
  157.     DATADIR=$MY_BASEDIR_VERSION/var
  158.   # Or just give up and use our compiled-in default
  159.   else
  160.     DATADIR=@localstatedir@
  161.   fi
  162. fi
  163.  
  164. if test ! -x "$bindir/mysqlcheck"
  165. then
  166.   echo "Can't find program '$bindir/mysqlcheck'"
  167.   echo "Please restart with --basedir=mysql-install-directory"
  168.   exit 1
  169. fi
  170.  
  171. if test ! -f "$DATADIR/mysql/user.frm"
  172. then
  173.   echo "Can't find data directory. Please restart with --datadir=path-to-data-dir"
  174.   exit 1
  175. fi
  176.  
  177. CHECK_FILE=$DATADIR/mysql_upgrade.info
  178.  
  179. if test -f $CHECK_FILE -a $force = 0
  180. then
  181.   version=`cat $CHECK_FILE`
  182.   if test "$version" = "@MYSQL_BASE_VERSION@"
  183.   then
  184.     if test $verbose = 1
  185.     then
  186.        echo "mysql_upgrade already done for this version"
  187.     fi
  188.     $bindir/mysql_fix_privilege_tables --silent $args
  189.     exit 0
  190.   fi
  191. fi
  192.  
  193. #
  194. # Run the upgrade
  195. #
  196.  
  197. check_args="--check-upgrade --all-databases --auto-repair --user=$user"
  198.  
  199. if test $verbose = 1
  200. then
  201.   echo "Running $bindir/mysqlcheck $args $check_args"
  202. fi
  203.  
  204. $bindir/mysqlcheck $check_args $args
  205. if [ $? = 0 ]
  206. then
  207.   # Remember base version so that we don't run this script again on the
  208.   # same base version
  209.   echo "@MYSQL_BASE_VERSION@" > $CHECK_FILE
  210. fi
  211.  
  212. $bindir/mysql_fix_privilege_tables --silent --user=$user $args
  213.