]> git.pld-linux.org Git - packages/percona-server.git/blame - mysql.init
- revert upgrade to 3.23.25 - ready to use 3.23.25 version is on
[packages/percona-server.git] / mysql.init
CommitLineData
53a28f77 1#!/bin/sh
2#
3# mysql A very fast and reliable SQL database engine
4#
ee9b6a50 5# chkconfig: 2345 90 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
19 msg_Network_Down MySQL
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
e9ca44ab 42MYSQL_DATA_DIR=`grep -m 1 "^[[:space:]]*datadir" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'`
43MYSQL_USER=`grep -m 1 "^[[:space:]]*user" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'`
44MYSQLD_PIDFILE=`grep -m 1 "^[[:space:]]*pid\-file" $MYSQLD_CONFIG 2>/dev/null| cut -f 2 -d= | tr -d '[:space:]'`
45
46if [ -z $MYSQL_DATA_DIR ]; then
47 echo "MySQL datadir $MYSQL_DATA_DIR not configured propely!"
48 echo "Edit $MYSQLD_CONFIG and configure it."
49 exit 1
50fi
51
52if [ -z $MYSQL_USER ]; then
53 echo "MySQL user not configured propely!"
54 echo "Edit $MYSQLD_CONFIG and configure it."
55 exit 1
56fi
57
58
83fddc12 59case "$1" in
60 start)
860cd80c 61 if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
e9ca44ab 62 echo "MySQL database not initialized. Try \"$0 init\" before start."
573e1dcc 63 exit 1
860cd80c 64 fi
e9ca44ab 65
66 # Check if the service is already running?
67 if [ -f /var/lock/subsys/mysql ]; then
68 msg_Already_Running MySQL
69 else
70 msg_starting MySQL
5678822f 71 busy
e9ca44ab 72
73 if [ ! -f $MYSQLD_ERRLOG ]; then
74 touch $MYSQLD_ERRLOG
75 fi
76 chown mysql.mysql $MYSQLD_ERRLOG
77 chmod 640 $MYSQLD_ERRLOG
78
79 /usr/sbin/mysqld --defaults-file=$MYSQLD_CONFIG >>$MYSQLD_ERRLOG 2>&1 &
8a2b6620 80 sleep 1
40c36bca
AF
81 deltext
82 if ps -C mysqld >/dev/null 2>&1; then
e9ca44ab 83 RETVAL=0
40c36bca 84 ok
8a2b6620 85 else
e9ca44ab 86 RETVAL=1
40c36bca 87 fail
8a2b6620 88 fi
ee9b6a50 89 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mysql
53a28f77 90 fi
53a28f77 91 ;;
92 stop)
ee9b6a50 93 if [ -f /var/lock/subsys/mysql ]; then
e9ca44ab 94 msg_stopping MySQL
ee9b6a50 95 killproc mysqld
e9ca44ab 96 sleep 1
97 rm -f /var/lock/subsys/mysql $MYSQLD_PIDFILE >/dev/null 2>&1
ee9b6a50 98 else
e9ca44ab 99 msg_Not_Running MySQL
ee9b6a50 100 exit 1
101 fi
53a28f77 102 ;;
103 status)
83fddc12 104 status mysqld
ee9b6a50 105 exit $?
53a28f77 106 ;;
107 restart|reload)
108 $0 stop
109 $0 start
110 ;;
573e1dcc 111 init)
112 # Check if not exist init database
e9ca44ab 113 if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
114 echo "Seems that database is initialized now. Remove by hand $MYSQL_DATA_DIR/mysql"
115 echo "before initialize database."
116 exit 1;
117 fi
118
119 show "Creating privilege mysql tables"
120 busy
121 TMP=/tmp TMPDIR=/tmp
f19b03aa 122
123 # Install this too in the user table
124 hostname=`hostname --fqdn | tr -d '[:space:]'`
40c36bca 125
e9ca44ab 126 # Check if hostname is valid
127 if [ -z "$hostname" ]; then
128 deltext
129 fail
130 echo "Sorry, the host name is not configured."
131 echo "Please configure the 'hostname' command to return a hostname."
132 exit 1
133 elif ! hostname -i >/dev/null 2>&1; then
134 deltext
135 fail
136 echo "Sorry, the host '$hostname' could not be looked up."
137 echo "Please configure the 'hostname' command to return a correct hostname."
138 exit 1
139 fi
140
141 #mysqld --bootstrap need whole (and only one) sql command in one line
142 create_db=""
143 create_db="$create_db CREATE TABLE db ( "
144 create_db="$create_db Host char(60) DEFAULT '' NOT NULL, "
145 create_db="$create_db Db char(32) DEFAULT '' NOT NULL,"
146 create_db="$create_db User char(16) DEFAULT '' NOT NULL, "
147 create_db="$create_db Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
148 create_db="$create_db Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
149 create_db="$create_db Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
150 create_db="$create_db Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
151 create_db="$create_db Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
152 create_db="$create_db Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
153 create_db="$create_db Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
154 create_db="$create_db References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
155 create_db="$create_db Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
156 create_db="$create_db Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
157 create_db="$create_db PRIMARY KEY Host (Host,Db,User), "
158 create_db="$create_db KEY User (User)"
159 create_db="$create_db );"
160
161 create_host=""
162 create_host="$create_host CREATE TABLE host ( "
163 create_host="$create_host Host char(60) DEFAULT '' NOT NULL, "
164 create_host="$create_host Db char(32) DEFAULT '' NOT NULL, "
165 create_host="$create_host Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
166 create_host="$create_host Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
167 create_host="$create_host Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
168 create_host="$create_host Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
169 create_host="$create_host Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
170 create_host="$create_host Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
171 create_host="$create_host Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
172 create_host="$create_host References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
173 create_host="$create_host Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
174 create_host="$create_host Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
175 create_host="$create_host PRIMARY KEY Host (Host,Db)"
176 create_host="$create_host );"
40c36bca 177
e9ca44ab 178 create_user=""
179 create_user="$create_user CREATE TABLE user ("
180 create_user="$create_user Host char(60) DEFAULT '' NOT NULL, "
181 create_user="$create_user User char(16) DEFAULT '' NOT NULL, "
182 create_user="$create_user Password char(16) DEFAULT '' NOT NULL, "
183 create_user="$create_user Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
184 create_user="$create_user Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
185 create_user="$create_user Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
186 create_user="$create_user Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
187 create_user="$create_user Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
188 create_user="$create_user Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
189 create_user="$create_user Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
190 create_user="$create_user Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
191 create_user="$create_user Process_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
192 create_user="$create_user File_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
193 create_user="$create_user Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
194 create_user="$create_user References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
195 create_user="$create_user Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
196 create_user="$create_user Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
197 create_user="$create_user PRIMARY KEY Host (Host,User)"
198 create_user="$create_user );"
199
200 create_func=""
201 create_func="$create_func CREATE TABLE func ( "
202 create_func="$create_func name char(64) DEFAULT '' NOT NULL, "
203 create_func="$create_func ret tinyint(1) DEFAULT '0' NOT NULL,"
204 create_func="$create_func dl char(128) DEFAULT '' NOT NULL, "
205 create_func="$create_func type enum ('function','aggregate') NOT NULL, "
206 create_func="$create_func PRIMARY KEY (name)"
207 create_func="$create_func ); "
208
209 create_tblpriv=""
210 create_tblpriv="$create_tblpriv CREATE TABLE tables_priv ( "
211 create_tblpriv="$create_tblpriv Host char(60) DEFAULT '' NOT NULL, "
212 create_tblpriv="$create_tblpriv Db char(60) DEFAULT '' NOT NULL, "
213 create_tblpriv="$create_tblpriv User char(16) DEFAULT '' NOT NULL,"
214 create_tblpriv="$create_tblpriv Table_name char(60) DEFAULT '' NOT NULL, "
215 create_tblpriv="$create_tblpriv Grantor char(77) DEFAULT '' NOT NULL, "
216 create_tblpriv="$create_tblpriv Timestamp timestamp(14), "
217 create_tblpriv="$create_tblpriv Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL, "
218 create_tblpriv="$create_tblpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
219 create_tblpriv="$create_tblpriv PRIMARY KEY (Host,Db,User,Table_name), "
220 create_tblpriv="$create_tblpriv KEY Grantor (Grantor)"
221 create_tblpriv="$create_tblpriv );"
222
223 create_colpriv=""
224 create_colpriv="$create_colpriv CREATE TABLE columns_priv ( "
225 create_colpriv="$create_colpriv Host char(60) DEFAULT '' NOT NULL, "
226 create_colpriv="$create_colpriv Db char(60) DEFAULT '' NOT NULL, "
227 create_colpriv="$create_colpriv User char(16) DEFAULT '' NOT NULL, "
228 create_colpriv="$create_colpriv Table_name char(60) DEFAULT '' NOT NULL, "
229 create_colpriv="$create_colpriv Column_name char(60) DEFAULT '' NOT NULL, "
230 create_colpriv="$create_colpriv Timestamp timestamp(14), "
231 create_colpriv="$create_colpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, "
232 create_colpriv="$create_colpriv PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
233 create_colpriv="$create_colpriv );"
234 if /usr/sbin/mysqld --bootstrap --skip-grant-tables \
235 --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA
236CREATE DATABASE mysql;
237use mysql;
238$create_db
239$inser_db
240$create_host
241$create_user
242$insert_user
243$create_func
244$create_tblpriv
245$create_colpriv
246#INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
247#INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
248INSERT INTO user VALUES ('localhost','mysql_logrotate','','N','N','N','N','N','N','Y','N','N','N','N','N','N','N');
249INSERT INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
250INSERT INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
251REPLACE INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
252REPLACE INTO user VALUES ('$hostname','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
40c36bca 253END_OF_DATA
e9ca44ab 254
255 then
256 deltext
257 ok
258 cat << END_OF_MSG
6a46c354 259
260PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!
e9ca44ab 261This is done with:
6a46c354 262
e9ca44ab 263/usr/bin/mysqladmin -u mysql password 'password'
f19b03aa 264/usr/bin/mysqladmin -h $hostname -u mysql password 'password'
e9ca44ab 265/usr/bin/mysqladmin -u mysql_logrotate password 'password'
6a46c354 266
267NOTE: mysql_logrotate password should be placed to /etc/mysqld.conf in
268mysqladmin section. See the manual for more instructions.
e9ca44ab 269
270END_OF_MSG
271 else
272 deltext
273 fail
274 cat << END_OF_MSG
275Installation of grant tables FAILED!
276
277Examine the logs in $MYSQL_DATA_DIR for more information. You can
278also try to start the mysqld demon with:
279
280/usr/sbin/mysqld --skip-grant &
281
282You can use the command line tool /usr/bin/mysql to connect to the mysql
283database and look at the grant tables:
284
285shell> /usr/bin/mysql -u mysql mysql
286mysql> show tables
287
288Try 'mysqld --help' if you have problems with paths. Setting on
289logging in /etc/mysqld.conf gives you a log in /var/log/mysql/log that
290may be helpful. The latest information about MySQL is available on the
291web at <http://www.mysql.com>.
292
293Please check PLD ftp site for newer versions of this package.
294
295Please consult the MySQL manual section: 'Problems running
296mysql_install_db', and the manual section that describes problems on
297your OS. Another information source is the MySQL email archive.
298Please check all of the above before mailing us! And if you do mail
299us, you MUST use the /usr/bin/mysqlbug script!
300
301END_OF_MSG
302
303 exit 1
304 fi
305
573e1dcc 306 ;;
53a28f77 307 *)
ee9b6a50 308 msg_Usage "$0 {start|stop|status|restart|reload|init}"
53a28f77 309 exit 1
83fddc12 310 ;;
53a28f77 311esac
40c36bca 312
ee9b6a50 313exit $RETVAL
This page took 0.076426 seconds and 4 git commands to generate.