summaryrefslogtreecommitdiff
path: root/scripts/mysql_fix_privilege_tables.sh
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2003-06-04 18:28:51 +0300
committerunknown <monty@narttu.mysql.fi>2003-06-04 18:28:51 +0300
commitb388eb004df7112b2ae0986457fc9d01131b71ea (patch)
treef2e86edc169afb1fed9cecefdecd9f13561780c9 /scripts/mysql_fix_privilege_tables.sh
parent15b3f3a0d8c11babff0f2e4dfa81c1716bcf533d (diff)
downloadmariadb-git-b388eb004df7112b2ae0986457fc9d01131b71ea.tar.gz
Added SQLSTATE to client/server protocol
bmove_allign -> bmove_align Added OLAP function ROLLUP Split mysql_fix_privilege_tables to a script and a .sql data file Added new (MEMROOT*) functions to avoid calling current_thd() when creating some common objects. Added table_alias_charset, for easier --lower-case-table-name handling Better SQL_MODE handling (Setting complex options also sets sub options) New (faster) assembler string functions for x86 BitKeeper/etc/ignore: added libmysqld/sql_state.c client/mysql.cc: Added SQLSTATE to error messages Added new function put_error() to be able to clean up some old code. client/mysqltest.c: Write ERROR SQLSTATE for all errors dbug/dbug.c: Portability fixes include/m_string.h: Rename bmove_allign as bmove_align include/mysql.h: Added SQLSTATE (for embedded version) include/mysql_com.h: Send correct SQLSTATE for the error to the client libmysql/libmysql.c: Changed default error state to HY000 Applied code cleanup patch libmysqld/Makefile.am: Added sql_state.cc libmysqld/libmysqld.c: Added sqlstate mysql-test/r/analyse.result: Updated results mysql-test/r/ansi.result: Updated results mysql-test/r/auto_increment.result: Updated results mysql-test/r/bdb-deadlock.result: Updated results mysql-test/r/bdb.result: Updated results mysql-test/r/comments.result: Updated results mysql-test/r/create.result: Updated results mysql-test/r/ctype_collate.result: Updated results mysql-test/r/delayed.result: Updated results mysql-test/r/delete.result: Updated results mysql-test/r/derived.result: Updated results mysql-test/r/distinct.result: Updated results mysql-test/r/drop.result: Updated results mysql-test/r/err000001.result: Updated results mysql-test/r/explain.result: Updated results mysql-test/r/flush.result: Updated results mysql-test/r/fulltext.result: Updated results mysql-test/r/func_gconcat.result: Updated results mysql-test/r/func_system.result: Updated results mysql-test/r/grant_cache.result: Updated results mysql-test/r/group_by.result: Updated results mysql-test/r/handler.result: Updated results mysql-test/r/heap.result: Updated results mysql-test/r/heap_btree.result: Updated results mysql-test/r/heap_hash.result: Updated results mysql-test/r/innodb.result: Updated results mysql-test/r/innodb_handler.result: Updated results mysql-test/r/insert_select.result: Updated results mysql-test/r/insert_update.result: Updated results mysql-test/r/join.result: Updated results mysql-test/r/join_outer.result: Updated results mysql-test/r/key.result: Updated results mysql-test/r/lock.result: Updated results mysql-test/r/lock_multi.result: Updated results mysql-test/r/merge.result: Updated results mysql-test/r/multi_update.result: Updated results mysql-test/r/myisam.result: Updated results mysql-test/r/null.result: Updated results mysql-test/r/olap.result: Updated results mysql-test/r/order_by.result: Updated results mysql-test/r/packet.result: Updated results mysql-test/r/query_cache.result: Updated results mysql-test/r/row.result: Updated results mysql-test/r/rpl000001.result: Updated results mysql-test/r/rpl000009.result: Updated results mysql-test/r/rpl_empty_master_crash.result: Updated results mysql-test/r/rpl_log.result: Updated results mysql-test/r/rpl_replicate_do.result: Updated results mysql-test/r/rpl_rotate_logs.result: Updated results mysql-test/r/select.result: Updated results mysql-test/r/select_safe.result: Updated results mysql-test/r/show_check.result: Updated results mysql-test/r/sql_mode.result: Updated results mysql-test/r/subselect.result: Updated results mysql-test/r/temp_table.result: Updated results mysql-test/r/truncate.result: Updated results mysql-test/r/type_blob.result: Updated results mysql-test/r/type_decimal.result: Updated results mysql-test/r/type_float.result: Updated results mysql-test/r/type_ranges.result: Updated results mysql-test/r/union.result: Updated results mysql-test/r/update.result: Updated results mysql-test/r/user_var.result: Updated results mysql-test/r/varbinary.result: Updated results mysql-test/r/variables.result: Updated results mysql-test/t/ansi.test: Test of sql_mode mysql-test/t/derived.test: Updated results mysql-test/t/func_system.test: Make this independen of the MySQL server name mysql-test/t/lowercase_table.test: Cleanup mysql-test/t/olap.test: A lot of new tests mysql-test/t/sql_mode.test: More test for sql_mode mysql-test/t/subselect.test: Added a few new tests (to find a bug in the item_ref code) scripts/Makefile.am: Added mysql_fix_privilege_tables.sql scripts/mysql_fix_privilege_tables.sh: Totally new script. This bascily just pipes mysql_fix_privilege_tables.sql through 'mysql' to 'mysqld' sql/Makefile.am: Added sql_state.cc sql/item.cc: Extended Item_field::eq() to be able to better match GROUP BY fields on the command line. Needed for ROLLUP sql/item.h: Added function to be able to avoid calling current_thd() when doing new Item. sql/item_sum.cc: Moved copy_or_same() and some reset() functions from item_sum.h Needed to be able to access thd->mem_root. sql/item_sum.h: Moved some functions to item_sum.cc Added make_unique() for ROLLUP sql/item_uniq.h: Fixed return value sql/mysql_priv.h: Updated MODE flags sql/mysqld.cc: Added ANSI as it's own mode Moved charset_info variables here Cleaned up handler_count handling (for NT) Added table_alias_charset, for easier --lower-case-table-name handling sql/net_serv.cc: New comment sql/protocol.cc: Send SQLSTATE to client sql/set_var.cc: Better SQL_MODE handling (Setting complex options also sets sub options) sql/set_var.h: Better SQL_MODE handling sql/sql_base.cc: Make alias depend on --lower-case-table-names Make find_item_in_list also check database name sql/sql_cache.cc: Indentation cleanup sql/sql_list.h: Added safety assert Addes support of alloc without current_thd() sql/sql_prepare.cc: Update after prototype change sql/sql_select.cc: Added ROLLUP sql/sql_select.h: structures for rollup sql/sql_show.cc: Easier SQL_MODE handling sql/sql_string.cc: Move CHARSET_INFO to mysqld (to be together with all other global variables) sql/sql_string.h: Added function to be able to avoid calling current_thd() when doing new Item. sql/sql_table.cc: Simpler --lower-case-table-name handling sql/sql_union.cc: Update after prototype change sql/sql_yacc.yy: ROLLUP sql/unireg.h: bmove_allign ->bmove_align strings/Makefile.am: Fix to be able to compile str_test.c strings/ctype.c: Removed empty lines strings/str_test.c: Added test of bmove_align strings/strings-x86.s: Faster bmove_align, bmove_upp and strmake strings/strings.asm: move_allg
Diffstat (limited to 'scripts/mysql_fix_privilege_tables.sh')
-rw-r--r--scripts/mysql_fix_privilege_tables.sh344
1 files changed, 149 insertions, 195 deletions
diff --git a/scripts/mysql_fix_privilege_tables.sh b/scripts/mysql_fix_privilege_tables.sh
index 05d6f3ffb71..5d392f719f0 100644
--- a/scripts/mysql_fix_privilege_tables.sh
+++ b/scripts/mysql_fix_privilege_tables.sh
@@ -1,212 +1,166 @@
#!/bin/sh
+# This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
+# through the mysql client program to the mysqld server
-root_password="$1"
+# Default values (Can be changed in my.cnf)
+password=""
host="localhost"
user="root"
-
-if test -z $1 ; then
- cmd="@bindir@/mysql -f --user=$user --host=$host mysql"
+sql_only=0
+basedir=""
+verbose=0
+args=""
+
+file=mysql_fix_privilege_tables.sql
+
+# The following code is almost identical to the code in mysql_install_db.sh
+
+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=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
+ --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
+ --password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
+ --host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
+ --sql|--sql-only) sql_only=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
+}
+
+# Get first arguments from the my.cfg file, groups [mysqld] and
+# [mysql_install_db], and then merge with the command line arguments
+if test -x ./bin/my_print_defaults
+then
+ print_defaults="./bin/my_print_defaults"
+elif test -x @bindr@/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
- root_password="$1"
- cmd="@bindir@/mysql -f --user=$user --password=$root_password --host=$host mysql"
+ print_defaults="my_print_defaults"
fi
-# Debian addition
-if [ "$1" = "--sql-only" ]; then
- root_password=""
- cmd="/usr/share/mysql/echo_stderr"
-fi
+parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
+parse_arguments PICK-ARGS-FROM-ARGV "$@"
-echo "This scripts updates the mysql.user, mysql.db, mysql.host and the"
-echo "mysql.func tables to MySQL 3.22.14 and above."
-echo ""
-echo "This is needed if you want to use the new GRANT functions,"
-echo "CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 3.23"
-echo ""
-echo "If you get 'Access denied' errors, you should run this script again"
-echo "and give the MySQL root user password as an argument!"
-
-echo "Converting all privilege tables to MyISAM format"
-$cmd <<END_OF_DATA
-ALTER TABLE user type=MyISAM;
-ALTER TABLE db type=MyISAM;
-ALTER TABLE host type=MyISAM;
-ALTER TABLE func type=MyISAM;
-ALTER TABLE columns_priv type=MyISAM;
-ALTER TABLE tables_priv type=MyISAM;
-END_OF_DATA
-
-
-# Fix old password format, add File_priv and func table
-echo ""
-echo "If your tables are already up to date or partially up to date you will"
-echo "get some warnings about 'Duplicated column name'. You can safely ignore these!"
-
-$cmd <<END_OF_DATA
-alter table user change password password char(16) NOT NULL;
-alter table user add File_priv enum('N','Y') NOT NULL;
-CREATE TABLE if not exists func (
- name char(64) DEFAULT '' NOT NULL,
- ret tinyint(1) DEFAULT '0' NOT NULL,
- dl char(128) DEFAULT '' NOT NULL,
- type enum ('function','aggregate') NOT NULL,
- PRIMARY KEY (name)
-);
-END_OF_DATA
-echo ""
-
-# Add the new grant colums
-
-echo "Creating Grant Alter and Index privileges if they don't exists"
-echo "You can ignore any Duplicate column errors"
-$cmd <<END_OF_DATA
-alter table user add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
-alter table host add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
-alter table db add Grant_priv enum('N','Y') NOT NULL,add References_priv enum('N','Y') NOT NULL,add Index_priv enum('N','Y') NOT NULL,add Alter_priv enum('N','Y') NOT NULL;
-END_OF_DATA
-res=$?
-echo ""
-
-# If the new grant columns didn't exists, copy File -> Grant
-# and Create -> Alter, Index, References
-
-if test $res = 0
+if test -z "$basedir"
then
- echo "Setting default privileges for the new grant, index and alter privileges"
- $cmd <<END_OF_DATA
- UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
- UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
- UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv;
-END_OF_DATA
- echo ""
+ basedir=@prefix@
+ bindir=@bindir@
+ execdir=@libexecdir@
+ pkgdatadir=@pkgdatadir@
+else
+ bindir="$basedir/bin"
+ if test -x "$basedir/libexec/mysqld"
+ then
+ execdir="$basedir/libexec"
+ elif test -x "@libexecdir@/mysqld"
+ then
+ execdir="@libexecdir@"
+ else
+ execdir="$basedir/bin"
+ fi
fi
-#
-# The second alter changes ssl_type to new 4.0.2 format
-
-echo "Adding columns needed by GRANT .. REQUIRE (openssl)"
-echo "You can ignore any Duplicate column errors"
-$cmd <<END_OF_DATA
-ALTER TABLE user
-ADD ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL,
-ADD ssl_cipher BLOB NOT NULL,
-ADD x509_issuer BLOB NOT NULL,
-ADD x509_subject BLOB NOT NULL;
-ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL;
-END_OF_DATA
-echo ""
-
-#
-# Create tables_priv and columns_priv if they don't exists
-#
-
-echo "Creating the new table and column privilege tables"
-
-$cmd <<END_OF_DATA
-CREATE TABLE IF NOT EXISTS tables_priv (
- Host char(60) DEFAULT '' NOT NULL,
- Db char(60) DEFAULT '' NOT NULL,
- User char(16) DEFAULT '' NOT NULL,
- Table_name char(60) DEFAULT '' NOT NULL,
- Grantor char(77) DEFAULT '' NOT NULL,
- Timestamp timestamp(14),
- Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,
- Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
- PRIMARY KEY (Host,Db,User,Table_name)
-);
-CREATE TABLE IF NOT EXISTS columns_priv (
- Host char(60) DEFAULT '' NOT NULL,
- Db char(60) DEFAULT '' NOT NULL,
- User char(16) DEFAULT '' NOT NULL,
- Table_name char(60) DEFAULT '' NOT NULL,
- Column_name char(59) DEFAULT '' NOT NULL,
- Timestamp timestamp(14),
- Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,
- PRIMARY KEY (Host,Db,User,Table_name,Column_name)
-);
-END_OF_DATA
-
-#
-# Name change of Type -> Column_priv from MySQL 3.22.12
-#
-
-echo "Changing name of columns_priv.Type -> columns_priv.Column_priv"
-echo "You can ignore any Unknown column errors from this"
-
-$cmd <<END_OF_DATA
-ALTER TABLE columns_priv change Type Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL;
-END_OF_DATA
-echo ""
-
-#
-# Add the new 'type' column to the func table.
-#
-
-echo "Fixing the func table"
-echo "You can ignore any Duplicate column errors"
-
-$cmd <<EOF
-alter table func add type enum ('function','aggregate') NOT NULL;
-EOF
-echo ""
-
-#
-# Change the user,db and host tables to MySQL 4.0 format
-#
-
-echo "Adding new fields used by MySQL 4.0.2 to the privilege tables"
-echo "You can ignore any Duplicate column errors"
-
-$cmd <<END_OF_DATA
-alter table user
-add Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER alter_priv,
-add Super_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Show_db_priv,
-add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Super_priv,
-add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Create_tmp_table_priv,
-add Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Lock_tables_priv,
-add Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Execute_priv,
-add Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Repl_slave_priv;
-END_OF_DATA
-
-if test $? -eq "0"
+# The following test is to make this script compatible with the 4.0 where
+# the first argument was the password
+if test -z $password
then
- # Convert privileges so that users have similar privileges as before
- echo ""
- echo "Updating new privileges in MySQL 4.0.2 from old ones"
- $cmd <<END_OF_DATA
- update user set show_db_priv= select_priv, super_priv=process_priv, execute_priv=process_priv, create_tmp_table_priv='Y', Lock_tables_priv='Y', Repl_slave_priv=file_priv, Repl_client_priv=file_priv where user<>"";
-END_OF_DATA
- echo ""
+ password=`echo $args | sed -e 's/ *//g'`
fi
-# Add fields that can be used to limit number of questions and connections
-# for some users.
-
-$cmd <<END_OF_DATA
-alter table user
-add max_questions int(11) NOT NULL AFTER x509_subject,
-add max_updates int(11) unsigned NOT NULL AFTER max_questions,
-add max_connections int(11) unsigned NOT NULL AFTER max_updates;
-END_OF_DATA
-
-# Increase password length to handle new passwords
-
-@bindir@/mysql -f --user=root --password="$root_password" --host="$host" mysql <<END_OF_DATA
-alter table user
-change password password char(45) not null;
-END_OF_DATA
-
+if test -z $password ; then
+ cmd="$bindir/mysql -f --user=$user --host=$host mysql"
+else
+ cmd="$bindir/mysql -f --user=$user --password=$password --host=$host mysql"
+fi
+if test $sql_only = 1
+then
+ cmd="cat"
+fi
+# Find where mysql_fix_privilege_tables.sql is located
+for i in $basedir/support-files $basedir/share $basedir/share/mysql \
+ $basedir/scripts @pkgdatadir@ . ./scripts
+do
+ if test -f $i/$file
+ then
+ pkgdatadir=$i
+ fi
+done
+
+sql_file="$pkgdatadir/$file"
+if test ! -f $sql_file
+then
+ echo "Could not find file '$file'."
+ echo "Please use --basedir to specify the directory where MySQL is installed"
+ exit 1
+fi
-#
-# Add Create_tmp_table_priv and Lock_tables_priv to db and host
-#
+s_echo()
+{
+ if test $sql_only = 0
+ then
+ echo $1
+ fi
+}
+
+s_echo "This scripts updates all the mysql privilege tables to be usable by"
+s_echo "MySQL 4.0 and above."
+s_echo ""
+s_echo "This is needed if you want to use the new GRANT functions,"
+s_echo "CREATE AGGREGATE FUNCTION or want to use the more secure passwords in 4.1"
+s_echo ""
+
+if test $verbose = 1
+then
+ s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
+ s_echo "as this just means that your tables where already up to date."
+ s_echo "This script is safe to run even if your tables are already up to date!"
+ s_echo ""
+fi
-$cmd <<END_OF_DATA
-alter table db
-add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
-add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
-alter table host
-add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,
-add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
-END_OF_DATA
+if test $verbose = 0
+then
+ cat $sql_file | $cmd > /dev/null 2>&1
+else
+ cat $sql_file | $cmd > /dev/null
+fi
+if test $? = 0
+then
+ s_echo "done"
+else
+ s_echo "Got a failure from command:"
+ s_echo "$cmd"
+ s_echo "Please check the above output and try again."
+ if test $verbose = 0
+ then
+ s_echo ""
+ s_echo "Running the script with the --verbose option may give you some information"
+ s_echo "of what went wrong."
+ fi
+ s_echo ""
+ s_echo "If you get an 'Access denied' error, you should run this script again and"
+ s_echo "give the MySQL root user password as an argument with the --password= option"
+fi