Skip to content

Commit 2b5d765

Browse files
committedNov 28, 2011
update mysql install document
1 parent ea96356 commit 2b5d765

File tree

4 files changed

+148
-80
lines changed

4 files changed

+148
-80
lines changed
 

‎mysql/install.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
MYSQL_VER=5.0.33
3+
MYSQL_VER=5.1.59
44

55
cd /usr/local/src
66

@@ -12,7 +12,7 @@ fi
1212

1313
if [ ! -f mysql-${MYSQL_VER}.tar.gz ];
1414
then
15-
wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.33.tar.gz
15+
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-${MYSQL_VER}.tar.gz
1616
fi
1717

1818

@@ -23,7 +23,6 @@ cd mysql-${MYSQL_VER}
2323
INSTALL_DIR=/usr/local/mysql-${MYSQL_VER}
2424

2525
./configure --prefix=${INSTALL_DIR} \
26-
--datadir=/usr/local/var/data/mysql \
2726
--with-charset=utf8 \
2827
--with-extra-charsets=ujis,sjis,cp932 \
2928
--enable-thread-safe-client

‎mysql/install.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ chown mysql:mysql -R /usr/local/var/mysql
2020
chmod go-rwx /usr/local/var/mysql
2121

2222
su mysql
23-
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/var/mysql
23+
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/var/mysql --basedir=/usr/local/mysql
2424

25-
mkdir /usr/local/mysql/conf
26-
27-
28-
cp ./my.cf /usr/local/mysql/conf/my.cf
25+
cp ./my.cnf /usr/local/var/mysql/
2926

3027
# copy mysql.server from this directory
3128
cp ./mysql.server /etc/init.d/

‎mysql/my.cf ‎mysql/my.cnf

+15-27
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# an important part, or systems up to 128M where MySQL is used together with
55
# other programs (such as a web server)
66
#
7-
# You can copy this file to
8-
# /etc/my.cnf to set global options,
9-
# mysql-data-dir/my.cnf to set server-specific options (in this
10-
# installation this directory is /usr/local/mysql-5.0.33/var) or
11-
# ~/.my.cnf to set user-specific options.
7+
# MySQL programs look for option files in a set of
8+
# locations which depend on the deployment platform.
9+
# You can copy this option file to one of those
10+
# locations. For information about these locations, see:
11+
# http://dev.mysql.com/doc/mysql/en/option-files.html
1212
#
1313
# In this file, you can use all long options that a program supports.
1414
# If you want to know which options a program supports, run the program
@@ -27,15 +27,18 @@ socket = /tmp/mysql.sock
2727
port = 3306
2828
socket = /tmp/mysql.sock
2929
skip-locking
30-
key_buffer = 16M
30+
key_buffer_size = 16M
3131
max_allowed_packet = 1M
32-
table_cache = 64
32+
table_open_cache = 64
3333
sort_buffer_size = 512K
3434
net_buffer_length = 8K
3535
read_buffer_size = 256K
3636
read_rnd_buffer_size = 512K
3737
myisam_sort_buffer_size = 8M
3838

39+
datadir=/usr/local/var/mysql
40+
basedir=/usr/local/mysql
41+
3942
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
4043
# if all processes that need to connect to mysqld run on the same host.
4144
# All interaction with mysqld must be made via Unix sockets or named pipes.
@@ -48,6 +51,9 @@ myisam_sort_buffer_size = 8M
4851
# binary logging is required for replication
4952
log-bin=mysql-bin
5053

54+
# binary logging format - mixed recommended
55+
binlog_format=mixed
56+
5157
# required unique id between 1 and 2^32 - 1
5258
# defaults to 1 if master-host is not set
5359
# but will not function as a master if omitted
@@ -108,19 +114,10 @@ server-id = 1
108114
# binary logging - not required for slaves, but recommended
109115
#log-bin=mysql-bin
110116

111-
# Point the following paths to different dedicated disks
112-
#tmpdir = /tmp/
113-
#log-update = /path-to-dedicated-directory/hostname
114-
115-
# Uncomment the following if you are using BDB tables
116-
#bdb_cache_size = 4M
117-
#bdb_max_lock = 10000
118-
119117
# Uncomment the following if you are using InnoDB tables
120-
innodb_data_home_dir = /usr/local/var/mysql/
118+
innodb_data_home_dir = /usr/local/var/mysql
121119
innodb_data_file_path = ibdata1:10M:autoextend
122120
innodb_log_group_home_dir = /usr/local/var/mysql/
123-
innodb_log_arch_dir = /usr/local/var/mysql
124121
# You can set .._buffer_pool_size up to 50 - 80 %
125122
# of RAM but beware of setting memory usage too high
126123
innodb_buffer_pool_size = 16M
@@ -140,20 +137,11 @@ no-auto-rehash
140137
# Remove the next comment character if you are not familiar with SQL
141138
#safe-updates
142139

143-
[isamchk]
144-
key_buffer = 20M
145-
sort_buffer_size = 20M
146-
read_buffer = 2M
147-
write_buffer = 2M
148-
149140
[myisamchk]
150-
key_buffer = 20M
141+
key_buffer_size = 20M
151142
sort_buffer_size = 20M
152143
read_buffer = 2M
153144
write_buffer = 2M
154145

155146
[mysqlhotcopy]
156147
interactive-timeout
157-
158-
[safe_mysqld]
159-
errlog=/usr/local/var/mysql/mysqld.log

‎mysql/mysql.server

100644100755
+129-45
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
# Short-Description: start and stop MySQL
2525
# Description: MySQL is a very fast and reliable SQL database engine.
2626
### END INIT INFO
27-
28-
# If you install MySQL on some other places than /usr/local/mysql-5.0.33, then you
27+
28+
# If you install MySQL on some other places than /usr/local/mysql-5.1.59, then you
2929
# have to do one of the following things for this script to work:
3030
#
3131
# - Run this script from within the MySQL installation directory
@@ -43,8 +43,15 @@
4343
# If you change base dir, you must also change datadir. These may get
4444
# overwritten by settings in the MySQL configuration files.
4545

46-
basedir=
47-
datadir=
46+
basedir=/usr/local/mysql
47+
datadir=/usr/local/var/mysql
48+
49+
# Default value, in seconds, afterwhich the script should timeout waiting
50+
# for server start.
51+
# Value here is overriden by value in my.cnf.
52+
# 0 means don't wait at all
53+
# Negative numbers mean to wait indefinitely
54+
service_startup_timeout=900
4855

4956
# The following variables are only set for letting mysql.server find things.
5057

@@ -55,14 +62,14 @@ use_mysqld_safe=1
5562
user=mysql
5663
if test -z "$basedir"
5764
then
58-
basedir=/usr/local/mysql
59-
bindir=/usr/local/mysql/bin
65+
basedir=/usr/local/mysql-5.1.59
66+
bindir=/usr/local/mysql-5.1.59/bin
6067
if test -z "$datadir"
6168
then
62-
datadir=/usr/local/var/mysql
69+
datadir=/usr/local/mysql-5.1.59/var
6370
fi
64-
sbindir=/usr/local/mysql/sbin
65-
libexecdir=/usr/local/mysql/libexec
71+
sbindir=/usr/local/mysql-5.1.59/sbin
72+
libexecdir=/usr/local/mysql-5.1.59/libexec
6673
else
6774
bindir="$basedir/bin"
6875
if test -z "$datadir"
@@ -115,17 +122,18 @@ parse_server_arguments() {
115122
case "$arg" in
116123
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
117124
bindir="$basedir/bin"
118-
if test -z "$datadir_set"; then
119-
datadir="$basedir/data"
120-
fi
121-
sbindir="$basedir/sbin"
122-
libexecdir="$basedir/libexec"
125+
if test -z "$datadir_set"; then
126+
datadir="$basedir/data"
127+
fi
128+
sbindir="$basedir/sbin"
129+
libexecdir="$basedir/libexec"
123130
;;
124131
--datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
125-
datadir_set=1
126-
;;
132+
datadir_set=1
133+
;;
127134
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
128135
--pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
136+
--service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
129137
--use-mysqld_safe) use_mysqld_safe=1;;
130138
--use-manager) use_mysqld_safe=0;;
131139
esac
@@ -142,29 +150,55 @@ parse_manager_arguments() {
142150
}
143151

144152
wait_for_pid () {
153+
verb="$1"
154+
manager_pid="$2" # process ID of the program operating on the pid-file
145155
i=0
146-
while test $i -lt 35 ; do
147-
sleep 1
148-
case "$1" in
156+
avoid_race_condition="by checking again"
157+
while test $i -ne $service_startup_timeout ; do
158+
159+
case "$verb" in
149160
'created')
161+
# wait for a PID-file to pop into existence.
150162
test -s $pid_file && i='' && break
151163
;;
152164
'removed')
165+
# wait for this PID-file to disappear
153166
test ! -s $pid_file && i='' && break
154167
;;
155168
*)
156-
echo "wait_for_pid () usage: wait_for_pid created|removed"
169+
echo "wait_for_pid () usage: wait_for_pid created|removed manager_pid"
157170
exit 1
158171
;;
159172
esac
173+
174+
# if manager isn't running, then pid-file will never be updated
175+
if test -n "$manager_pid"; then
176+
if kill -0 "$manager_pid" 2>/dev/null; then
177+
: # the manager still runs
178+
else
179+
# The manager may have exited between the last pid-file check and now.
180+
if test -n "$avoid_race_condition"; then
181+
avoid_race_condition=""
182+
continue # Check again.
183+
fi
184+
185+
# there's nothing that will affect the file.
186+
log_failure_msg "Manager of pid-file quit without updating file."
187+
return 1 # not waiting any more.
188+
fi
189+
fi
190+
160191
echo $echo_n ".$echo_c"
161192
i=`expr $i + 1`
193+
sleep 1
162194
done
163195

164196
if test -z "$i" ; then
165197
log_success_msg
198+
return 0
166199
else
167200
log_failure_msg
201+
return 1
168202
fi
169203
}
170204

@@ -189,7 +223,7 @@ else
189223
dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
190224
for d in $dirs
191225
do
192-
d=`echo $d | sed -e 's/[ ]//g'`
226+
d=`echo $d | sed -e 's/[ ]//g'`
193227
if test -x "$d/bin/my_print_defaults"
194228
then
195229
print_defaults="$d/bin/my_print_defaults"
@@ -224,8 +258,7 @@ else
224258
fi
225259

226260
parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
227-
228-
# Look for the pidfile
261+
# Look for the pidfile
229262
parse_manager_arguments `$print_defaults $extra_args manager`
230263

231264
#
@@ -250,12 +283,11 @@ else
250283
esac
251284
fi
252285

253-
# Safeguard (relative paths, core dumps..)
254-
cd $basedir
255-
256286
case "$mode" in
257287
'start')
258288
# Start daemon
289+
# Safeguard (relative paths, core dumps..)
290+
cd $basedir
259291

260292
manager=$bindir/mysqlmanager
261293
if test -x $libexecdir/mysqlmanager
@@ -276,29 +308,35 @@ case "$mode" in
276308
fi
277309
# Give extra arguments to mysqld with the my.cnf file. This script may
278310
# be overwritten at next upgrade.
279-
$manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 &
280-
wait_for_pid created
311+
"$manager" \
312+
--mysqld-safe-compatible \
313+
--user="$user" \
314+
--pid-file="$pid_file" >/dev/null 2>&1 &
315+
wait_for_pid created $!; return_value=$?
281316

282317
# Make lock for RedHat / SuSE
283318
if test -w /var/lock/subsys
284319
then
285320
touch /var/lock/subsys/mysqlmanager
286321
fi
322+
exit $return_value
287323
elif test -x $bindir/mysqld_safe
288324
then
289325
# Give extra arguments to mysqld with the my.cnf file. This script
290326
# may be overwritten at next upgrade.
291327
pid_file=$server_pid_file
292-
$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
293-
wait_for_pid created
328+
$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file \
329+
--language=/usr/local/mysql/share/mysql/english $other_args >/dev/null 2>&1 &
330+
wait_for_pid created $!; return_value=$?
294331

295332
# Make lock for RedHat / SuSE
296333
if test -w /var/lock/subsys
297334
then
298335
touch /var/lock/subsys/mysql
299336
fi
337+
exit $return_value
300338
else
301-
log_failure_msg "Couldn't find MySQL manager or server"
339+
log_failure_msg "Couldn't find MySQL manager ($manager) or server ($bindir/mysqld_safe)"
302340
fi
303341
;;
304342

@@ -319,16 +357,24 @@ case "$mode" in
319357
if test -s "$pid_file"
320358
then
321359
mysqlmanager_pid=`cat $pid_file`
322-
echo $echo_n "Shutting down MySQL"
323-
kill $mysqlmanager_pid
324-
# mysqlmanager should remove the pid_file when it exits, so wait for it.
325-
wait_for_pid removed
326-
360+
361+
if (kill -0 $mysqlmanager_pid 2>/dev/null)
362+
then
363+
echo $echo_n "Shutting down MySQL"
364+
kill $mysqlmanager_pid
365+
# mysqlmanager should remove the pid_file when it exits, so wait for it.
366+
wait_for_pid removed "$mysqlmanager_pid"; return_value=$?
367+
else
368+
log_failure_msg "MySQL manager or server process #$mysqlmanager_pid is not running!"
369+
rm $pid_file
370+
fi
371+
327372
# delete lock for RedHat / SuSE
328373
if test -f $lock_dir
329374
then
330375
rm -f $lock_dir
331376
fi
377+
exit $return_value
332378
else
333379
log_failure_msg "MySQL manager or server PID file could not be found!"
334380
fi
@@ -337,23 +383,61 @@ case "$mode" in
337383
'restart')
338384
# Stop the service and regardless of whether it was
339385
# running or not, start it again.
340-
$0 stop $other_args
341-
$0 start $other_args
386+
if $0 stop $other_args; then
387+
$0 start $other_args
388+
else
389+
log_failure_msg "Failed to stop running server, so refusing to try to start."
390+
exit 1
391+
fi
342392
;;
343393

344-
'reload')
394+
'reload'|'force-reload')
345395
if test -s "$server_pid_file" ; then
346-
mysqld_pid=`cat $server_pid_file`
396+
read mysqld_pid < $server_pid_file
347397
kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
348398
touch $server_pid_file
349399
else
350400
log_failure_msg "MySQL PID file could not be found!"
401+
exit 1
351402
fi
352403
;;
353-
354-
*)
355-
# usage
356-
echo "Usage: $0 {start|stop|restart|reload} [ MySQL server options ]"
357-
exit 1
404+
'status')
405+
# First, check to see if pid file exists
406+
if test -s "$server_pid_file" ; then
407+
read mysqld_pid < $server_pid_file
408+
if kill -0 $mysqld_pid 2>/dev/null ; then
409+
log_success_msg "MySQL running ($mysqld_pid)"
410+
exit 0
411+
else
412+
log_failure_msg "MySQL is not running, but PID file exists"
413+
exit 1
414+
fi
415+
else
416+
# Try to find appropriate mysqld process
417+
mysqld_pid=`pidof $libexecdir/mysqld`
418+
if test -z $mysqld_pid ; then
419+
if test "$use_mysqld_safe" = "0" ; then
420+
lockfile=/var/lock/subsys/mysqlmanager
421+
else
422+
lockfile=/var/lock/subsys/mysql
423+
fi
424+
if test -f $lockfile ; then
425+
log_failure_msg "MySQL is not running, but lock exists"
426+
exit 2
427+
fi
428+
log_failure_msg "MySQL is not running"
429+
exit 3
430+
else
431+
log_failure_msg "MySQL is running but PID file could not be found"
432+
exit 4
433+
fi
434+
fi
435+
;;
436+
*)
437+
# usage
438+
echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [ MySQL server options ]"
439+
exit 1
358440
;;
359441
esac
442+
443+
exit 0

0 commit comments

Comments
 (0)
Please sign in to comment.