You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
5.1 KiB

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