From 8f87bd6008b3580d20eba39442f475f23b15f6c0 Mon Sep 17 00:00:00 2001 From: "jperkin@production.mysql.com" <> Date: Thu, 26 Jul 2007 12:57:46 +0200 Subject: [PATCH] Clean up the mysql_install_db script to ensure that a sane environment is available and reduce the chance of failure. This should fix bug#28585 which is caused by the script being quite random in how it finds files it requires and not giving very good feedback to the user about what went wrong. Also update make_binary_distribution so that it provides the correct path to the required SQL scripts when generating mysql_install_db. The script only previously worked because of the permissive behaviour which looked around the current working directory before the "correct" location. This could lead to severe problems if the user happened to run the script from a location which contained older or even broken copies of the SQL scripts. We now require either a complete binary release (and the mysql_install_db script ran from inside the extracted archive), or an installed compiled tree, as this is the only way we can be sure everything that we need is available and ready to run. While working on this fix, also clean up the mysql_install_db script a lot to make it simpler, easier to read, and hopefully less prone to bugs in the future. --- scripts/make_binary_distribution.sh | 2 +- scripts/mysql_install_db.sh | 274 ++++++++++++++-------------- 2 files changed, 136 insertions(+), 140 deletions(-) diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index 9584721682f..dab1bbec956 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -318,7 +318,7 @@ if [ $BASE_SYSTEM != "netware" ] ; then copyfileto $BASE/bin scripts/* $BASE/bin/replace \@localstatedir\@ ./data \@bindir\@ ./bin \@scriptdir\@ \ ./bin \@libexecdir\@ ./bin \@sbindir\@ ./bin \@prefix\@ . \@HOSTNAME\@ \ - @HOSTNAME@ \@pkgdatadir\@ ./support-files \ + @HOSTNAME@ \@pkgdatadir\@ ./share \ < scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db $BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \ \@sbindir\@ ./bin \@libexecdir\@ ./bin \ diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 934d245db15..c5d532ee4ed 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -18,26 +18,65 @@ # # All unrecognized arguments to this script are passed to mysqld. +force=0 in_rpm=0 +ip_only=0 windows=0 -defaults="" -user="" case "$1" in - --no-defaults|--defaults-file=*|--defaults-extra-file=*) - defaults="$1"; shift - ;; + --no-defaults|--defaults-file=*|--defaults-extra-file=*) + defaults="$1"; shift + ;; esac +usage() +{ + cat <&1` if [ $? -ne 0 ] @@ -244,39 +247,35 @@ then fi fi -if test "$ip_only" = "1" +if test "$ip_only" -eq 1 then - ip=`echo "$resolved" | awk '/ /{print $6}'` - hostname=$ip + hostname=`echo "$resolved" | awk '/ /{print $6}'` fi # Create database directories mysql & test -if test ! -d $ldata; then - mkdir $ldata; - chmod 700 $ldata ; -fi -if test ! -d $ldata/mysql; then - mkdir $ldata/mysql; - chmod 700 $ldata/mysql ; -fi -if test ! -d $ldata/test; then - mkdir $ldata/test; - chmod 700 $ldata/test ; -fi -if test -w / -a ! -z "$user"; then - chown $user $ldata $ldata/mysql $ldata/test; -fi +for dir in $ldata $ldata/mysql $ldata/test +do + if test ! -d $dir + then + mkdir -p $dir + chmod 700 $dir + fi + if test -w / -a ! -z "$user" + then + chown $user $dir + fi +done -if test -n "$user"; then +if test -n "$user" +then args="$args --user=$user" fi # Peform the install of system tables mysqld_bootstrap="${MYSQLD_BOOTSTRAP-$mysqld}" mysqld_install_cmd_line="$mysqld_bootstrap $defaults $mysqld_opt --bootstrap \ ---basedir=$basedir --datadir=$ldata --skip-innodb \ ---skip-bdb --skip-ndbcluster $args --max_allowed_packet=8M \ ---net_buffer_length=16K" + --basedir=$basedir --datadir=$ldata --skip-innodb --skip-bdb \ + --skip-ndbcluster $args --max_allowed_packet=8M --net_buffer_length=16K" # Pipe mysql_system_tables.sql to "mysqld --bootstrap" s_echo "Installing MySQL system tables..." @@ -284,23 +283,20 @@ if `(echo "use mysql;"; cat $create_system_tables $fill_system_tables) | $mysqld then s_echo "OK" - if test -n "$fill_help_tables" + s_echo "Filling help tables..." + # Pipe fill_help_tables.sql to "mysqld --bootstrap" + if `(echo "use mysql;"; cat $fill_help_tables) | $mysqld_install_cmd_line` then - s_echo "Filling help tables..." - # Pipe fill_help_tables.sql to "mysqld --bootstrap" - if `(echo "use mysql;"; cat $fill_help_tables) | $mysqld_install_cmd_line` - then - # Fill suceeded - s_echo "OK" - else - echo "" - echo "WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED!" - echo "The \"HELP\" command might not work properly" - echo "" - fi + # Fill suceeded + s_echo "OK" + else + echo + echo "WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED!" + echo "The \"HELP\" command might not work properly" + echo fi - s_echo "" + s_echo s_echo "To start mysqld at boot time you have to copy" s_echo "support-files/mysql.server to the right place for your system" s_echo @@ -319,7 +315,7 @@ then echo "$bindir/mysqladmin -u root -h $hostname password 'new-password'" echo "See the manual for more instructions." - if test "$in_rpm" = "0" + if test "$in_rpm" -eq 0 then echo "You can start the MySQL daemon with:" echo "cd @prefix@ ; $bindir/mysqld_safe &"