~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to scripts/mysql_install_db.sh

  • Committer: Monty Taylor
  • Date: 2008-07-02 14:35:48 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702143548-onj30ry0sugr01uw
Removed all references to THREAD.

Show diffs side-by-side

added added

removed removed

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