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