home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / mysql / scripts / mysql_install_db < prev    next >
Encoding:
Text File  |  2008-04-17  |  13.0 KB  |  426 lines

  1. #!/bin/sh
  2. # Copyright (C) 2002-2003 MySQL AB
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; version 2 of the License.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program; if not, write to the Free Software
  12. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  13.  
  14. # This scripts creates the MySQL Server system tables
  15. #
  16. # All unrecognized arguments to this script are passed to mysqld.
  17.  
  18. basedir=""
  19. ldata=""
  20. srcdir=""
  21.  
  22. args=""
  23. defaults=""
  24. mysqld_opt=""
  25. user=""
  26.  
  27. force=0
  28. in_rpm=0
  29. ip_only=0
  30. windows=0
  31.  
  32. usage()
  33. {
  34.   cat <<EOF
  35. Usage: $0 [OPTIONS]
  36.   --basedir=path       The path to the MySQL installation directory.
  37.   --datadir=path       The path to the MySQL data directory.
  38.   --force              Causes mysql_install_db to run even if DNS does not
  39.                        work.  In that case, grant table entries that normally
  40.                        use hostnames will use IP addresses.
  41.   --ldata=path         The path to the MySQL data directory.
  42.   --rpm                For internal use.  This option is used by RPM files
  43.                        during the MySQL installation process.
  44.   --skip-name-resolve  Use IP addresses rather than hostnames when creating
  45.                        grant table entries.  This option can be useful if
  46.                        your DNS does not work.
  47.   --srcdir=path        For internal use.  The directory under which
  48.                        mysql_install_db looks for support files such as the
  49.                        error message file and the file for popoulating the
  50.                        help tables.
  51.   --user=user_name     The login username to use for running mysqld.  Files
  52.                        and directories created by mysqld will be owned by this
  53.                        user.  You must be root to use this option.  By default
  54.                        mysqld runs using your current login name and files and
  55.                        directories that it creates will be owned by you.
  56.   --windows            For internal use.  This option is used for creating
  57.                        Windows distributions.
  58.  
  59. All other options are passed to the mysqld program
  60.  
  61. EOF
  62.   exit 1
  63. }
  64.  
  65. s_echo()
  66. {
  67.   if test "$in_rpm" -eq 0 -a "$windows" -eq 0
  68.   then
  69.     echo "$1"
  70.   fi
  71. }
  72.  
  73. parse_arg()
  74. {
  75.   echo "$1" | sed -e 's/^[^=]*=//'
  76. }
  77.  
  78. parse_arguments()
  79. {
  80.   # We only need to pass arguments through to the server if we don't
  81.   # handle them here.  So, we collect unrecognized options (passed on
  82.   # the command line) into the args variable.
  83.   pick_args=
  84.   if test "$1" = PICK-ARGS-FROM-ARGV
  85.   then
  86.     pick_args=1
  87.     shift
  88.   fi
  89.  
  90.   for arg
  91.   do
  92.     case "$arg" in
  93.       --force) force=1 ;;
  94.       --basedir=*) basedir=`parse_arg "$arg"` ;;
  95.       --srcdir=*)  srcdir=`parse_arg "$arg"` ;;
  96.       --ldata=*|--datadir=*) ldata=`parse_arg "$arg"` ;;
  97.       --user=*)
  98.         # Note that the user will be passed to mysqld so that it runs
  99.         # as 'user' (crucial e.g. if log-bin=/some_other_path/
  100.         # where a chown of datadir won't help)
  101.      user=`parse_arg "$arg"` ;;
  102.       --skip-name-resolve) ip_only=1 ;;
  103.       --verbose) verbose=1 ;; # Obsolete
  104.       --rpm) in_rpm=1 ;;
  105.       --help) usage ;;
  106.       --no-defaults|--defaults-file=*|--defaults-extra-file=*)
  107.         defaults="$arg" ;;
  108.  
  109.       --windows)
  110.     # This is actually a "cross bootstrap" argument used when
  111.         # building the MySQL system tables on a different host
  112.         # than the target. The platform independent
  113.         # files that are created in --datadir on the host can
  114.         # be copied to the target system, the most common use for
  115.         # this feature is in the windows installer which will take
  116.         # the files from datadir and include them as part of the install
  117.         # package.
  118.          windows=1 ;;
  119.  
  120.       *)
  121.         if test -n "$pick_args"
  122.         then
  123.           # This sed command makes sure that any special chars are quoted,
  124.           # so the arg gets passed exactly to the server.
  125.           # XXX: This is broken; true fix requires using eval and proper
  126.           # quoting of every single arg ($basedir, $ldata, etc.)
  127.           #args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'`
  128.           args="$args $arg"
  129.         fi
  130.         ;;
  131.     esac
  132.   done
  133. }
  134.  
  135. # Try to find a specific file within --basedir which can either be a binary
  136. # release or installed source directory and return the path.
  137. find_in_basedir()
  138. {
  139.   case "$1" in
  140.     --dir)
  141.       return_dir=1; shift
  142.       ;;
  143.   esac
  144.  
  145.   file=$1; shift
  146.  
  147.   for dir in "$@"
  148.   do
  149.     if test -f "$basedir/$dir/$file"
  150.     then
  151.       if test -n "$return_dir"
  152.       then
  153.         echo "$basedir/$dir"
  154.       else
  155.         echo "$basedir/$dir/$file"
  156.       fi
  157.       break
  158.     fi
  159.   done
  160. }
  161.  
  162. missing_in_basedir()
  163. {
  164.   echo "FATAL ERROR: Could not find $* inside --basedir"
  165.   echo
  166.   echo "When using --basedir you must point either into a MySQL binary"
  167.   echo "distribution directory or a compiled tree previously populated"
  168.   echo "by 'make install'"
  169. }
  170.  
  171. # Ok, let's go.  We first need to parse arguments which are required by
  172. # my_print_defaults so that we can execute it first, then later re-parse
  173. # the command line to add any extra bits that we need.
  174. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  175.  
  176. # We can now find my_print_defaults, either in the supplied --basedir
  177. # location or in the installed area.
  178. if test -n "$basedir"
  179. then
  180.   print_defaults=`find_in_basedir my_print_defaults bin extra`
  181.   if ! test -x "$print_defaults"
  182.   then
  183.     missing_in_basedir my_print_defaults
  184.     exit 1
  185.   fi
  186. else
  187.   print_defaults="@bindir@/my_print_defaults"
  188.   if ! test -x "$print_defaults"
  189.   then
  190.     echo "FATAL ERROR: Could not find $print_defaults"
  191.     echo
  192.     echo "If you are using a binary release, you must run this script from"
  193.     echo "within the directory the archive extracted into.  If you compiled"
  194.     echo "MySQL yourself you must run 'make install' first."
  195.     exit 1
  196.   fi
  197. fi
  198.  
  199. # Now we can get arguments from the groups [mysqld] and [mysql_install_db]
  200. # in the my.cfg file, then re-run to merge with command line arguments.
  201. parse_arguments `$print_defaults $defaults mysqld mysql_install_db`
  202. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  203.  
  204. # Path to MySQL installation directory
  205. if test -z "$basedir"
  206. then
  207.   basedir="@prefix@"
  208.   bindir="@bindir@"
  209.   mysqld="@libexecdir@/mysqld"
  210.   pkgdatadir="@pkgdatadir@"
  211. else
  212.   bindir="$basedir/bin"
  213.   # We set up bootstrap-specific paths later, so skip this for --windows
  214.   if test "$windows" -eq 0
  215.   then
  216.     pkgdatadir=`find_in_basedir --dir fill_help_tables.sql share share/mysql`
  217.     if test -z "$pkgdatadir"
  218.     then
  219.       missing_in_basedir fill_help_tables.sql
  220.       exit 1
  221.     fi
  222.     mysqld=`find_in_basedir mysqld libexec sbin bin`
  223.     if ! test -x "$mysqld"
  224.     then
  225.       missing_in_basedir mysqld
  226.       exit 1
  227.     fi
  228.   fi
  229. fi
  230.  
  231. # Path to data directory
  232. if test -z "$ldata"
  233. then
  234.   ldata="@localstatedir@"
  235. fi
  236.  
  237. # Set up paths to SQL scripts required for bootstrap and ensure they exist.
  238. if test -n "$srcdir"
  239. then
  240.   pkgdatadir="$srcdir/scripts"
  241. fi
  242.  
  243. fill_help_tables="$pkgdatadir/fill_help_tables.sql"
  244. create_system_tables="$pkgdatadir/mysql_system_tables.sql"
  245. fill_system_tables="$pkgdatadir/mysql_system_tables_data.sql"
  246.  
  247. for f in $fill_help_tables $create_system_tables $fill_system_tables
  248. do
  249.   if test ! -f "$f"
  250.   then
  251.     echo "FATAL ERROR: Could not find SQL file '$f'"
  252.     exit 1
  253.   fi
  254. done
  255.  
  256. # Set up Windows-specific paths
  257. if test "$windows" -eq 1
  258. then
  259.   mysqld="./sql/mysqld"
  260.   if test -n "$srcdir" -a -f "$srcdir/sql/share/english/errmsg.sys"
  261.   then
  262.     mysqld_opt="--language=$srcdir/sql/share/english"
  263.   else
  264.     mysqld_opt="--language=./sql/share/english"
  265.   fi
  266. fi
  267.  
  268. # Make sure mysqld is available in default location (--basedir option is
  269. # already tested above).
  270. if test ! -x "$mysqld"
  271. then
  272.   echo "FATAL ERROR: $mysqld not found!"
  273.   exit 1
  274. fi
  275.  
  276. # Try to determine the hostname
  277. hostname=`@HOSTNAME@`
  278.  
  279. # Check if hostname is valid
  280. if test "$windows" -eq 0 -a "$in_rpm" -eq 0 -a "$force" -eq 0
  281. then
  282.   resolved=`$bindir/resolveip $hostname 2>&1`
  283.   if [ $? -ne 0 ]
  284.   then
  285.     resolved=`$bindir/resolveip localhost 2>&1`
  286.     if [ $? -ne 0 ]
  287.     then
  288.       echo "Neither host '$hostname' nor 'localhost' could be looked up with"
  289.       echo "$bindir/resolveip"
  290.       echo "Please configure the 'hostname' command to return a correct"
  291.       echo "hostname."
  292.       echo "If you want to solve this at a later stage, restart this script"
  293.       echo "with the --force option"
  294.       exit 1
  295.     fi
  296.     echo "WARNING: The host '$hostname' could not be looked up with resolveip."
  297.     echo "This probably means that your libc libraries are not 100 % compatible"
  298.     echo "with this binary MySQL version. The MySQL daemon, mysqld, should work"
  299.     echo "normally with the exception that host name resolving will not work."
  300.     echo "This means that you should use IP addresses instead of hostnames"
  301.     echo "when specifying MySQL privileges !"
  302.   fi
  303. fi
  304.  
  305. if test "$ip_only" -eq 1
  306. then
  307.   hostname=`echo "$resolved" | awk '/ /{print $6}'`
  308. fi
  309.  
  310. # Create database directories mysql & test
  311. for dir in $ldata $ldata/mysql $ldata/test
  312. do
  313.   if test ! -d $dir
  314.   then
  315.     mkdir -p $dir
  316.     chmod 700 $dir
  317.   fi
  318.   if test -w / -a ! -z "$user"
  319.   then
  320.     chown $user $dir
  321.   fi
  322. done
  323.  
  324. if test -n "$user"
  325. then
  326.   args="$args --user=$user"
  327. fi
  328.  
  329. # Peform the install of system tables
  330. mysqld_bootstrap="${MYSQLD_BOOTSTRAP-$mysqld}"
  331. mysqld_install_cmd_line="$mysqld_bootstrap $defaults $mysqld_opt --bootstrap \
  332.   --basedir=$basedir --datadir=$ldata --skip-innodb --skip-bdb \
  333.   --skip-ndbcluster $args --max_allowed_packet=8M --net_buffer_length=16K"
  334.  
  335. # Pipe mysql_system_tables.sql to "mysqld --bootstrap"
  336. s_echo "Installing MySQL system tables..."
  337. if `(echo "use mysql;"; cat $create_system_tables $fill_system_tables) | $mysqld_install_cmd_line`
  338. then
  339.   s_echo "OK"
  340.  
  341.   s_echo "Filling help tables..."
  342.   # Pipe fill_help_tables.sql to "mysqld --bootstrap"
  343.   if `(echo "use mysql;"; cat $fill_help_tables) | $mysqld_install_cmd_line`
  344.   then
  345.     # Fill suceeded
  346.     s_echo "OK"
  347.   else
  348.     echo
  349.     echo "WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED!"
  350.     echo "The \"HELP\" command might not work properly"
  351.     echo
  352.   fi
  353.  
  354.   s_echo
  355.   s_echo "To start mysqld at boot time you have to copy"
  356.   s_echo "support-files/mysql.server to the right place for your system"
  357.   s_echo
  358.  
  359.   if test "$windows" -eq 0
  360.   then
  361.     # A root password should of course also be set on Windows!
  362.     # The reason for not displaying these prompts here is that when
  363.     # executing this script with the --windows argument the script
  364.     # is used to generate system tables mainly used by the
  365.     # windows installer. And thus the password should not be set until
  366.     # those files has been copied to the target system
  367.     echo "PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !"
  368.     echo "To do so, start the server, then issue the following commands:"
  369.     echo "$bindir/mysqladmin -u root password 'new-password'"
  370.     echo "$bindir/mysqladmin -u root -h $hostname password 'new-password'"
  371.     echo
  372.     echo "Alternatively you can run:"
  373.     echo "$bindir/mysql_secure_installation"
  374.     echo
  375.     echo "which will also give you the option of removing the test"
  376.     echo "databases and anonymous user created by default.  This is"
  377.     echo "strongly recommended for production servers."
  378.     echo
  379.     echo "See the manual for more instructions."
  380.     echo
  381.  
  382.     if test "$in_rpm" -eq 0
  383.     then
  384.       echo "You can start the MySQL daemon with:"
  385.       echo "cd @prefix@ ; $bindir/mysqld_safe &"
  386.       echo
  387.       echo "You can test the MySQL daemon with mysql-test-run.pl"
  388.       echo "cd mysql-test ; perl mysql-test-run.pl"
  389.       echo
  390.     fi
  391.     echo "Please report any problems with the @scriptdir@/mysqlbug script!"
  392.     echo
  393.     echo "The latest information about MySQL is available on the web at"
  394.     echo "http://www.mysql.com"
  395.     echo "Support MySQL by buying support/licenses at http://shop.mysql.com"
  396.   fi
  397.   exit 0
  398. else
  399.   echo "Installation of system tables failed!"
  400.   echo
  401.   echo "Examine the logs in $ldata for more information."
  402.   echo "You can try to start the mysqld daemon with:"
  403.   echo "$mysqld --skip-grant &"
  404.   echo "and use the command line tool"
  405.   echo "$bindir/mysql to connect to the mysql"
  406.   echo "database and look at the grant tables:"
  407.   echo
  408.   echo "shell> $bindir/mysql -u root mysql"
  409.   echo "mysql> show tables"
  410.   echo
  411.   echo "Try 'mysqld --help' if you have problems with paths. Using --log"
  412.   echo "gives you a log in $ldata that may be helpful."
  413.   echo
  414.   echo "The latest information about MySQL is available on the web at"
  415.   echo "http://www.mysql.com"
  416.   echo "Please consult the MySQL manual section: 'Problems running mysql_install_db',"
  417.   echo "and the manual section that describes problems on your OS."
  418.   echo "Another information source is the MySQL email archive."
  419.   echo "Please check all of the above before mailing us!"
  420.   echo "And if you do mail us, you MUST use the @scriptdir@/mysqlbug script!"
  421.   exit 1
  422. fi
  423.