summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorunknown <holyfoot@deer.(none)>2006-02-17 10:52:32 +0400
committerunknown <holyfoot@deer.(none)>2006-02-17 10:52:32 +0400
commit437afc71235b9cab8b7e801e1473818e8604e6ff (patch)
treee1075b7c3e3c1d0a91edf078cf69906180661d4c /scripts
parentf504554358d1ef9e46d5e9902b2a22399bc9e14a (diff)
downloadmariadb-git-437afc71235b9cab8b7e801e1473818e8604e6ff.tar.gz
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
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am3
-rw-r--r--scripts/mysql_upgrade.sh185
2 files changed, 188 insertions, 0 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 394e24c7c32..0f68b484f41 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -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
diff --git a/scripts/mysql_upgrade.sh b/scripts/mysql_upgrade.sh
new file mode 100644
index 00000000000..db5dc6a9516
--- /dev/null
+++ b/scripts/mysql_upgrade.sh
@@ -0,0 +1,185 @@
+#!/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