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