You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
11 KiB

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