Commit bf840404 authored by unknown's avatar unknown
Browse files

WL#2645 (CHECK TABLE FOR UPGRADE)

necessary implementation in the server
mysql_upgrade script added


client/mysqlcheck.c:
  --check-upgrade option added
include/my_base.h:
  errcode added
include/myisam.h:
  option added
scripts/Makefile.am:
  mysql_upgrade script added
sql/handler.cc:
  checks for old types/bugs added
sql/handler.h:
  declarations regarding checks for upgrade
sql/lex.h:
  sym added
sql/share/errmsg.txt:
  error message added
sql/slave.cc:
  now ha_repair is for public use
sql/sql_table.cc:
  upgrade in ha_repair implemented
sql/sql_yacc.yy:
  CHECK ... FOR UPGRADE added to syntax
parent 74f6299e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
               opt_compress = 0, opt_databases = 0, opt_fast = 0,
               opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
               opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
               tty_password = 0, opt_frm = 0;
               tty_password = 0, opt_frm = 0, opt_upgrade= 0;
static uint verbose = 0, opt_mysql_port=0;
static my_string opt_mysql_unix_port = 0;
static char *opt_password = 0, *current_user = 0, 
@@ -78,6 +78,9 @@ static struct my_option my_long_options[] =
  {"check-only-changed", 'C',
   "Check only tables that have changed since last check or haven't been closed properly.",
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"check-upgrade", 'g',
   "Check tables for version dependent changes.May be used with auto-repair to correct tables requiring version dependent updates.",
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
   (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
   0, 0, 0},
@@ -268,6 +271,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
  case 'r':
    what_to_do = DO_REPAIR;
    break;
  case 'g':
    what_to_do= DO_CHECK;
    opt_upgrade= 1;
    break;
  case 'W':
#ifdef __WIN__
    opt_protocol = MYSQL_PROTOCOL_PIPE;
@@ -525,6 +532,7 @@ static int handle_request_for_tables(char *tables, uint length)
    if (opt_medium_check)       end = strmov(end, " MEDIUM"); /* Default */
    if (opt_extended)           end = strmov(end, " EXTENDED");
    if (opt_check_only_changed) end = strmov(end, " CHANGED");
    if (opt_upgrade)            end = strmov(end, " FOR UPGRADE");
    break;
  case DO_REPAIR:
    op = "REPAIR";
+2 −1
Original line number Diff line number Diff line
@@ -346,8 +346,9 @@ enum ha_base_keytype {
#define HA_ERR_NO_CONNECTION     157  /* Could not connect to storage engine */
#define HA_ERR_NULL_IN_SPATIAL   158  /* NULLs are not supported in spatial index */
#define HA_ERR_TABLE_DEF_CHANGED 159  /* The table changed in storage engine */
#define HA_ERR_TABLE_NEEDS_UPGRADE 160  /* The table changed in storage engine */

#define HA_ERR_LAST              159  /*Copy last error nr.*/
#define HA_ERR_LAST              160  /*Copy last error nr.*/
/* Add error numbers before HA_ERR_LAST and change it accordingly. */
#define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)

+1 −0
Original line number Diff line number Diff line
@@ -368,6 +368,7 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
*/

#define TT_USEFRM               1
#define TT_FOR_UPGRADE          2

#define O_NEW_INDEX	1		/* Bits set in out_flag */
#define O_NEW_DATA	2
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ bin_SCRIPTS = @server_scripts@ \
			mysqldumpslow \
			mysql_explain_log \
			mysql_tableinfo \
			mysql_upgrade \
			mysqld_multi \
			mysql_create_system_tables

@@ -59,6 +60,7 @@ EXTRA_SCRIPTS = make_binary_distribution.sh \
			mysql_explain_log.sh \
			mysqld_multi.sh \
			mysql_tableinfo.sh \
			mysql_upgrade.sh \
			mysqld_safe.sh \
			mysql_create_system_tables.sh

@@ -87,6 +89,7 @@ CLEANFILES = @server_scripts@ \
			mysqldumpslow \
			mysql_explain_log \
			mysql_tableinfo \
			mysql_upgrade \
			mysqld_multi \
			make_win_src_distribution \
			mysql_create_system_tables
+185 −0
Original line number Diff line number Diff line
#!/bin/sh
# Copyright (C) 2002-2003 MySQL AB
# For a more info consult the file COPYRIGHT distributed with this file.

# Runs mysqlcheck --check-upgrade in case it has not been done on this
# major MySQL version

# This script should always be run when upgrading from one major version
# to another (ie: 4.1 -> 5.0 -> 5.1)

#
# Note that in most cases one have to use '--password' as
# arguments as these needs to be passed on to the mysqlcheck command


user=root

case "$1" in
    --no-defaults|--defaults-file=*|--defaults-extra-file=*)
      defaults="$1"; shift
      ;;
esac

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=*) MY_BASEDIR_VERSION=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --ldata=*|--data=*|--datadir=*) DATADIR=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --force) force=1 ;;
      --verbose) verbose=1 ;;
      *)
        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.
          args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.=-]\),\\\\\1,g'`
        fi
        ;;
    esac
  done
}

#
# Find where my_print_defaults is
#

find_my_print_defaults () {
  if test -x ./bin/my_print_defaults
  then
    print_defaults="./bin/my_print_defaults"
  elif test -x ./extra/my_print_defaults
  then
    print_defaults="./extra/my_print_defaults"
  elif test -x @bindir@/my_print_defaults
  then
    print_defaults="@bindir@/my_print_defaults"
  elif test -x @bindir@/mysql_print_defaults
  then
    print_defaults="@bindir@/mysql_print_defaults"
  else
    print_defaults="my_print_defaults"
  fi
}

find_my_print_defaults

# Get first arguments from the my.cfg file, groups [mysqld] and
# [mysql_upgrade], and then merge with the command line arguments

args=
DATADIR=
bindir=
MY_BASEDIR_VERSION=
verbose=0
force=0

parse_arguments `$print_defaults $defaults mysqld mysql_upgrade`
parse_arguments PICK-ARGS-FROM-ARGV "$@"

#
# Try to find where binaries are installed
#

MY_PWD=`pwd`
# Check for the directories we would expect from a binary release install
if test -z "$MY_BASEDIR_VERSION"
then
  if test -f ./share/mysql/english/errmsg.sys -a -x ./bin/mysqld
  then
    MY_BASEDIR_VERSION=$MY_PWD            # Where bin, share and data are
    bindir="$MY_BASEDIR_VERSION/bin"
  # Check for the directories we would expect from a source install
  elif test -f ./share/mysql/english/errmsg.sys -a -x ./libexec/mysqld
  then
    MY_BASEDIR_VERSION=$MY_PWD            # Where libexec, share and var are
    bindir="$MY_BASEDIR_VERSION/bin"
# Since we didn't find anything, used the compiled-in defaults
  else
    MY_BASEDIR_VERSION=@prefix@
    bindir=@bindir@
  fi
else
  bindir="$MY_BASEDIR_VERSION/bin"
fi

#
# Try to find the data directory
#

if test -z "$DATADIR"
then
  # Try where the binary installs put it
  if test -d $MY_BASEDIR_VERSION/data/mysql
  then
    DATADIR=$MY_BASEDIR_VERSION/data
  # Next try where the source installs put it
  elif test -d $MY_BASEDIR_VERSION/var/mysql
  then
    DATADIR=$MY_BASEDIR_VERSION/var
  # Or just give up and use our compiled-in default
  else
    DATADIR=@localstatedir@
  fi
fi

if test ! -x "$bindir/mysqlcheck"
then
  echo "Can't find program '$bindir/mysqlcheck'"
  echo "Please restart with --basedir=mysql-install-directory"
  exit 1
fi

if test ! -f "$DATADIR/mysql/user.frm"
then
  echo "Can't find data directory. Please restart with --datadir=path-to-data-dir"
  exit 1
fi

CHECK_FILE=$DATADIR/mysql_upgrade.info

if test -f $CHECK_FILE -a $force = 0
then
  version=`cat $CHECK_FILE`
  if test "$version" = "@MYSQL_BASE_VERSION@"
  then
    if test $verbose = 1
    then
       echo "mysql_upgrade already done for this version"
    fi
    $bindir/mysql_fix_privilege_tables --silent $args
    exit 0
  fi
fi

#
# Run the upgrade
#

check_args="--check-upgrade --all-databases --auto-repair --user=$user"

if test $verbose = 1
then
  echo "Running $bindir/mysqlcheck $args $check_args"
fi

$bindir/mysqlcheck $check_args $args
if [ $? = 0 ]
then
  # Remember base version so that we don't run this script again on the
  # same base version
  echo "@MYSQL_BASE_VERSION@" > $CHECK_FILE
fi

$bindir/mysql_fix_privilege_tables --silent --user=$user $args
Loading