]> git.pld-linux.org Git - packages/mysql.git/blame_incremental - mysql.init
- revert upgrade under main trunk, 3.23.x series is prepared under
[packages/mysql.git] / mysql.init
... / ...
CommitLineData
1#!/bin/sh
2#
3# mysql A very fast and reliable SQL database engine
4#
5# chkconfig: 2345 90 25
6#
7# description: A very fast and reliable SQL database engine.
8#
9# pidfile: /var/lib/mysql/mysqld.pid
10
11# Source function library
12. /etc/rc.d/init.d/functions
13
14# Get network config
15. /etc/sysconfig/network
16
17# Check that networking is up.
18if is_no "${NETWORKING}"; then
19 msg_Network_Down MySQL
20 exit 1
21fi
22
23MYSQLD_ERRLOG=/var/log/mysql/err
24MYSQLD_CONFIG=/etc/mysqld.conf
25
26# Get service config
27if [ -f /etc/sysconfig/mysql ] ; then
28 . /etc/sysconfig/mysql
29fi
30
31# Daemon don't dies if config doesn't exists
32if [ ! -f $MYSQLD_CONFIG ]; then
33 echo "MySQL config $MYSQLD_CONFIG not exists"
34 exit 1
35fi
36
37if [ ! -f $MYSQLD_CONFIG ]; then
38 echo "MySQL config $MYSQLD_CONFIG not exists"
39 exit 1
40fi
41
42eval `awk '
43/^[ \t]*\[.*\][ \t]*$/ {
44 match($0,/\[.*\]/)
45 section=substr($0,RSTART+1,RSTART+RLENGTH-3)
46}
47section=="mysqld" && $2~"=" {
48 if ($1=="datadir") {
49 printf("MYSQL_DATA_DIR=%s;", $3)
50 } else if ($1=="user") {
51 printf("MYSQL_USER=%s;", $3)
52 } else if ($1=="pid-file") {
53 printf("MYSQL_PIDFILE=%s;", $3)
54 }
55}
56END {
57 print "export MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE"
58}
59' /etc/mysqld.conf`
60
61if [ -z $MYSQL_DATA_DIR ]; then
62 echo "MySQL datadir $MYSQL_DATA_DIR not configured propely!"
63 echo "Edit $MYSQLD_CONFIG and configure it."
64 exit 1
65fi
66
67if [ -z $MYSQL_USER ]; then
68 echo "MySQL user not configured propely!"
69 echo "Edit $MYSQLD_CONFIG and configure it."
70 exit 1
71fi
72
73
74case "$1" in
75 start)
76 if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
77 echo "MySQL database not initialized. Try \"$0 init\" before start."
78 exit 1
79 fi
80
81 # Check if the service is already running?
82 if [ -f /var/lock/subsys/mysql ]; then
83 msg_Already_Running MySQL
84 else
85 msg_starting MySQL
86 busy
87
88 if [ ! -f $MYSQLD_ERRLOG ]; then
89 touch $MYSQLD_ERRLOG
90 fi
91 chown mysql.mysql $MYSQLD_ERRLOG
92 chmod 640 $MYSQLD_ERRLOG
93
94 /usr/sbin/mysqld --defaults-file=$MYSQLD_CONFIG >>$MYSQLD_ERRLOG 2>&1 &
95 sleep 1
96 deltext
97 if ps -C mysqld >/dev/null 2>&1; then
98 RETVAL=0
99 ok
100 else
101 RETVAL=1
102 fail
103 fi
104 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mysql
105 fi
106 ;;
107 stop)
108 if [ -f /var/lock/subsys/mysql ]; then
109 msg_stopping MySQL
110 killproc mysqld
111 sleep 1
112 rm -f /var/lock/subsys/mysql $MYSQLD_PIDFILE >/dev/null 2>&1
113 else
114 msg_Not_Running MySQL
115 exit 1
116 fi
117 ;;
118 status)
119 status mysqld
120 exit $?
121 ;;
122 restart|reload)
123 $0 stop
124 $0 start
125 ;;
126 init)
127 # Check if not exist init database
128 if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
129 echo "Seems that database is initialized now. Remove by hand $MYSQL_DATA_DIR/mysql"
130 echo "before initialize database."
131 exit 1;
132 fi
133
134 show "Creating privilege mysql tables"
135 busy
136 TMP=/tmp TMPDIR=/tmp
137
138 # Install this too in the user table
139 hostname="`hostname --fqdn | tr -d '[:space:]'`"
140
141 # Check if hostname is valid
142 if [ -z "$hostname" ]; then
143 deltext
144 fail
145 echo "Sorry, the host name is not configured."
146 echo "Please configure the 'hostname' command to return a hostname."
147 exit 1
148 elif ! hostname -i >/dev/null 2>&1; then
149 deltext
150 fail
151 echo "Sorry, the host '$hostname' could not be looked up."
152 echo "Please configure the 'hostname' command to return a correct hostname."
153 exit 1
154 fi
155
156 # Initialize variables
157 c_d="" i_d=""
158 c_h="" i_h=""
159 c_u="" i_u=""
160 c_f="" i_f=""
161 c_t="" c_c=""
162
163 # Check for old tables
164 if test ! -f $mdata/db.frm
165 then
166 # mysqld --bootstrap wants one command/line
167 c_d="$c_d CREATE TABLE db ("
168 c_d="$c_d Host char(60) DEFAULT '' NOT NULL,"
169 c_d="$c_d Db char(64) DEFAULT '' NOT NULL,"
170 c_d="$c_d User char(16) DEFAULT '' NOT NULL,"
171 c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
172 c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
173 c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
174 c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
175 c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
176 c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
177 c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
178 c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
179 c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
180 c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
181 c_d="$c_d PRIMARY KEY Host (Host,Db,User),"
182 c_d="$c_d KEY User (User)"
183 c_d="$c_d )"
184 c_d="$c_d comment='Database privileges';"
185
186 i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
187 INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');"
188 fi
189
190 if test ! -f $mdata/host.frm
191 then
192 c_h="$c_h CREATE TABLE host ("
193 c_h="$c_h Host char(60) DEFAULT '' NOT NULL,"
194 c_h="$c_h Db char(64) DEFAULT '' NOT NULL,"
195 c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
196 c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
197 c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
198 c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
199 c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
200 c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
201 c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
202 c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
203 c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
204 c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
205 c_h="$c_h PRIMARY KEY Host (Host,Db)"
206 c_h="$c_h )"
207 c_h="$c_h comment='Host privileges; Merged with database privileges';"
208 fi
209
210 if test ! -f $mdata/user.frm
211 then
212 c_u="$c_u CREATE TABLE user ("
213 c_u="$c_u Host char(60) DEFAULT '' NOT NULL,"
214 c_u="$c_u User char(16) DEFAULT '' NOT NULL,"
215 c_u="$c_u Password char(16) DEFAULT '' NOT NULL,"
216 c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
217 c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
218 c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
219 c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
220 c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
221 c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
222 c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
223 c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
224 c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
225 c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
226 c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
227 c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
228 c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
229 c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
230 c_u="$c_u PRIMARY KEY Host (Host,User)"
231 c_u="$c_u )"
232 c_u="$c_u comment='Users and global privileges';"
233
234 i_u="INSERT INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
235 INSERT INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
236
237 REPLACE INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
238 REPLACE INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
239
240 INSERT INTO user VALUES ('localhost','mysql_logrotate','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');"
241 fi
242
243 if test ! -f $mdata/func.frm
244 then
245 c_f="$c_f CREATE TABLE func ("
246 c_f="$c_f name char(64) DEFAULT '' NOT NULL,"
247 c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL,"
248 c_f="$c_f dl char(128) DEFAULT '' NOT NULL,"
249 c_f="$c_f type enum ('function','aggregate') NOT NULL,"
250 c_f="$c_f PRIMARY KEY (name)"
251 c_f="$c_f )"
252 c_f="$c_f comment='User defined functions';"
253 fi
254
255 if test ! -f $mdata/tables_priv.frm
256 then
257 c_t="$c_t CREATE TABLE tables_priv ("
258 c_t="$c_t Host char(60) DEFAULT '' NOT NULL,"
259 c_t="$c_t Db char(64) DEFAULT '' NOT NULL,"
260 c_t="$c_t User char(16) DEFAULT '' NOT NULL,"
261 c_t="$c_t Table_name char(60) DEFAULT '' NOT NULL,"
262 c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL,"
263 c_t="$c_t Timestamp timestamp(14),"
264 c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,"
265 c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
266 c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name),"
267 c_t="$c_t KEY Grantor (Grantor)"
268 c_t="$c_t )"
269 c_t="$c_t comment='Table privileges';"
270 fi
271
272 if test ! -f $mdata/columns_priv.frm
273 then
274 c_c="$c_c CREATE TABLE columns_priv ("
275 c_c="$c_c Host char(60) DEFAULT '' NOT NULL,"
276 c_c="$c_c Db char(64) DEFAULT '' NOT NULL,"
277 c_c="$c_c User char(16) DEFAULT '' NOT NULL,"
278 c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL,"
279 c_c="$c_c Column_name char(64) DEFAULT '' NOT NULL,"
280 c_c="$c_c Timestamp timestamp(14),"
281 c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
282 c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
283 c_c="$c_c )"
284 c_c="$c_c comment='Column privileges';"
285 fi
286
287 if /usr/sbin/mysqld --bootstrap --skip-grant-tables \
288 --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA
289CREATE DATABASE mysql;
290use mysql;
291$c_d
292$i_d
293
294$c_h
295$i_h
296
297$c_u
298$i_u
299
300$c_f
301$i_f
302
303$c_t
304$c_c
305END_OF_DATA
306 then
307 deltext
308 ok
309 cat << END_OF_MSG
310
311PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!
312This is done with:
313
314/usr/bin/mysqladmin -u mysql password 'password'
315/usr/bin/mysqladmin -h $hostname -u mysql password 'password'
316/usr/bin/mysqladmin -u mysql_logrotate password 'password'
317
318NOTE: mysql_logrotate password should be placed to /etc/mysqld.conf in
319mysqladmin section. See the manual for more instructions.
320
321END_OF_MSG
322 else
323 deltext
324 fail
325 cat << END_OF_MSG
326Installation of grant tables FAILED!
327
328Examine the logs in $MYSQL_DATA_DIR for more information. You can
329also try to start the mysqld demon with:
330
331/usr/sbin/mysqld --skip-grant &
332
333You can use the command line tool /usr/bin/mysql to connect to the mysql
334database and look at the grant tables:
335
336shell> /usr/bin/mysql -u mysql mysql
337mysql> show tables
338
339Try 'mysqld --help' if you have problems with paths. Setting on
340logging in /etc/mysqld.conf gives you a log in /var/log/mysql/log that
341may be helpful. The latest information about MySQL is available on the
342web at <http://www.mysql.com>.
343
344Please check PLD ftp site for newer versions of this package.
345
346Please consult the MySQL manual section: 'Problems running
347mysql_install_db', and the manual section that describes problems on
348your OS. Another information source is the MySQL email archive.
349Please check all of the above before mailing us! And if you do mail
350us, you MUST use the /usr/bin/mysqlbug script!
351
352END_OF_MSG
353
354 exit 1
355 fi
356 ;;
357 *)
358 msg_Usage "$0 {start|stop|status|restart|reload|init}"
359 exit 1
360 ;;
361esac
362
363exit $RETVAL
This page took 0.053707 seconds and 4 git commands to generate.