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.

433 lines
13 KiB

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