]> git.pld-linux.org Git - packages/percona-server.git/blame - mysql.init
- new from scratch
[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
c42b39b6 17MYSQL_DATA_DIR=/var/lib/mysql
40c36bca
AF
18MYSQL_USER=mysql
19
53a28f77 20# Get service config
860cd80c 21if [ -f /etc/sysconfig/mysql ] ; then
22 . /etc/sysconfig/mysql
23 if [ -z "${MYSQL_DATA_DIR}" ]; then
c42b39b6 24 MYSQL_DATA_DIR=/var/lib/mysql
860cd80c 25 fi
860cd80c 26fi
53a28f77 27
28# Check that networking is up.
ee9b6a50 29if is_no "${NETWORKING}"; then
30 msg_Network_Down Mysql
53a28f77 31 exit 1
32fi
33
83fddc12 34case "$1" in
35 start)
573e1dcc 36 # Check if the service is already running?
860cd80c 37 if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
573e1dcc 38 echo "Mysq database not initialized. Try \"$0 init\" before start."
39 exit 1
860cd80c 40 fi
ee9b6a50 41
53a28f77 42 if [ ! -f /var/lock/subsys/mysql ]; then
ee9b6a50 43 msg_starting Mysql
5678822f 44 busy
40c36bca 45 /usr/sbin/mysqld -u $MYSQL_USER --datadir=$MYSQL_DATA_DIR >>/var/log/mysql.log 2>&1 &
8a2b6620 46 sleep 1
40c36bca
AF
47 deltext
48 if ps -C mysqld >/dev/null 2>&1; then
49 ok
8a2b6620 50 else
40c36bca 51 fail
8a2b6620 52 fi
ee9b6a50 53 RETVAL=$?
54 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mysql
53a28f77 55 else
ee9b6a50 56 msg_Already_Running Mysql
53a28f77 57 fi
53a28f77 58 ;;
59 stop)
ee9b6a50 60 if [ -f /var/lock/subsys/mysql ]; then
61 msg_stopping Mysql
62 killproc mysqld
63 sleep 2
c42b39b6 64 rm -f /var/lock/subsys/mysql /var/lib/mysql/mysql.pid >/dev/null 2>&1
ee9b6a50 65 else
66 msg_Not_Running Mysql
67 exit 1
68 fi
53a28f77 69 ;;
70 status)
83fddc12 71 status mysqld
ee9b6a50 72 exit $?
53a28f77 73 ;;
74 restart|reload)
75 $0 stop
76 $0 start
77 ;;
573e1dcc 78 init)
79 # Check if not exist init database
80 if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
ee9b6a50 81 show "Creating privilege mysql tables"
16df4e61 82 busy
40c36bca
AF
83 TMP=/tmp TMPDIR=/tmp
84 hostname=`hostname` # Install this too in the user table
85
86 # Check if hostname is valid
87 resolved=`/usr/bin/resolveip $hostname 2>&1`
88 if [ $? -ne 0 ]; then
89 resolved=`/usr/bin/resolveip localhost 2>&1`
90 if [ $? -eq 0 ]; then
91 deltext
92 fail
93 echo "Sorry, the host '$hostname' could not be looked up."
94 echo "Please configure the 'hostname' command to return a correct hostname."
95 exit 1
96 fi
97 fi
98
99 # Create database directories mysql & test
100 if test ! -d $MYSQL_DATA_DIR/mysql; then
101 install -d -m700 -o $MYSQL_USER $MYSQL_DATA_DIR/mysql;
102 fi
103
104 #mysqld --bootstrap need whole (and only one) sql command in one line
105 create_db=""
106 create_db="$create_db CREATE TABLE db ( "
107 create_db="$create_db Host char(60) DEFAULT '' NOT NULL, "
108 create_db="$create_db Db char(32) DEFAULT '' NOT NULL,"
109 create_db="$create_db User char(16) DEFAULT '' NOT NULL, "
110 create_db="$create_db Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
111 create_db="$create_db Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
112 create_db="$create_db Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
113 create_db="$create_db Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
114 create_db="$create_db Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
115 create_db="$create_db Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
116 create_db="$create_db Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
117 create_db="$create_db References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
118 create_db="$create_db Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
119 create_db="$create_db Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
120 create_db="$create_db PRIMARY KEY Host (Host,Db,User), "
121 create_db="$create_db KEY User (User)"
122 create_db="$create_db );"
123
124 create_host=""
125 create_host="$create_host CREATE TABLE host ( "
126 create_host="$create_host Host char(60) DEFAULT '' NOT NULL, "
127 create_host="$create_host Db char(32) DEFAULT '' NOT NULL, "
128 create_host="$create_host Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
129 create_host="$create_host Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
130 create_host="$create_host Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
131 create_host="$create_host Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
132 create_host="$create_host Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
133 create_host="$create_host Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
134 create_host="$create_host Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
135 create_host="$create_host References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
136 create_host="$create_host Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
137 create_host="$create_host Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
138 create_host="$create_host PRIMARY KEY Host (Host,Db)"
139 create_host="$create_host );"
140
141 create_user=""
142 create_user="$create_user CREATE TABLE user ("
143 create_user="$create_user Host char(60) DEFAULT '' NOT NULL, "
144 create_user="$create_user User char(16) DEFAULT '' NOT NULL, "
145 create_user="$create_user Password char(16) DEFAULT '' NOT NULL, "
146 create_user="$create_user Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
147 create_user="$create_user Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
148 create_user="$create_user Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
149 create_user="$create_user Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
150 create_user="$create_user Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
151 create_user="$create_user Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
152 create_user="$create_user Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
153 create_user="$create_user Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
154 create_user="$create_user Process_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
155 create_user="$create_user File_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
156 create_user="$create_user Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
157 create_user="$create_user References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
158 create_user="$create_user Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
159 create_user="$create_user Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
160 create_user="$create_user PRIMARY KEY Host (Host,User)"
161 create_user="$create_user );"
162
163 create_func=""
164 create_func="$create_func CREATE TABLE func ( "
165 create_func="$create_func name char(64) DEFAULT '' NOT NULL, "
166 create_func="$create_func ret tinyint(1) DEFAULT '0' NOT NULL,"
167 create_func="$create_func dl char(128) DEFAULT '' NOT NULL, "
168 create_func="$create_func type enum ('function','aggregate') NOT NULL, "
169 create_func="$create_func PRIMARY KEY (name)"
170 create_func="$create_func ); "
171
172 create_tblpriv=""
173 create_tblpriv="$create_tblpriv CREATE TABLE tables_priv ( "
174 create_tblpriv="$create_tblpriv Host char(60) DEFAULT '' NOT NULL, "
175 create_tblpriv="$create_tblpriv Db char(60) DEFAULT '' NOT NULL, "
176 create_tblpriv="$create_tblpriv User char(16) DEFAULT '' NOT NULL,"
177 create_tblpriv="$create_tblpriv Table_name char(60) DEFAULT '' NOT NULL, "
178 create_tblpriv="$create_tblpriv Grantor char(77) DEFAULT '' NOT NULL, "
179 create_tblpriv="$create_tblpriv Timestamp timestamp(14), "
180 create_tblpriv="$create_tblpriv Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL, "
181 create_tblpriv="$create_tblpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
182 create_tblpriv="$create_tblpriv PRIMARY KEY (Host,Db,User,Table_name), "
183 create_tblpriv="$create_tblpriv KEY Grantor (Grantor)"
184 create_tblpriv="$create_tblpriv );"
185
186 create_colpriv=""
187 create_colpriv="$create_colpriv CREATE TABLE columns_priv ( "
188 create_colpriv="$create_colpriv Host char(60) DEFAULT '' NOT NULL, "
189 create_colpriv="$create_colpriv Db char(60) DEFAULT '' NOT NULL, "
190 create_colpriv="$create_colpriv User char(16) DEFAULT '' NOT NULL, "
191 create_colpriv="$create_colpriv Table_name char(60) DEFAULT '' NOT NULL, "
192 create_colpriv="$create_colpriv Column_name char(60) DEFAULT '' NOT NULL, "
193 create_colpriv="$create_colpriv Timestamp timestamp(14), "
194 create_colpriv="$create_colpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, "
195 create_colpriv="$create_colpriv PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
196 create_colpriv="$create_colpriv );"
197
198 if /usr/sbin/mysqld --bootstrap --skip-grant-tables \
199 --basedir=/usr --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA
200 use mysql;
201 $create_db
202 $inser_db
203 $create_host
204 $create_user
205 $insert_user
206 $create_func
207 $create_tblpriv
208 $create_colpriv
209
210 INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
211 INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
212 INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
213 INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
214 REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
215 REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
216 INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
217 INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
218
219END_OF_DATA
220 then
221 deltext
222 ok
223 echo " PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !"
224 echo " This is done with:"
225 echo " /usr/bin/mysqladmin -u root password 'new-password'"
226 echo " See the manual for more instructions."
227 echo
228 else
229 deltext
230 fail
231 echo " Installation of grant tables failed!"
232 echo
233 echo " Examine the logs in $MYSQL_DATA_DIR for more information."
234 echo " You can also try to start the mysqld demon with:"
235 echo " /usr/sbin/mysqld --skip-grant &"
236 echo " You can use the command line tool"
237 echo " /usr/bin/mysql to connect to the mysql"
238 echo " database and look at the grant tables:"
239 echo
240 echo "shell> /usr/bin/mysql -u root mysql"
241 echo "mysql> show tables"
242 echo
243 echo "Try 'mysqld --help' if you have problems with paths. Using --log"
244 echo "gives you a log in $MYSQL_DATA_DIR that may be helpful."
245 echo
246 echo "The latest information about MySQL is available on the web at"
247 echo "http://www.mysql.com"
248 echo "Please consult the MySQL manual section: 'Problems running mysql_install_db',"
249 echo "and the manual section that describes problems on your OS."
250 echo "Another information source is the MySQL email archive."
251 echo "Please check all of the above before mailing us!"
252 echo "And if you do mail us, you MUST use the /usr/bin/mysqlbug script!"
253 exit 1
254 fi
255 else
256 echo "Semms that database is initialized now. Remove by hand $MYSQL_DATA_DIR/mysql"
257 echo "before initialize database.".
573e1dcc 258 fi
259 ;;
53a28f77 260 *)
ee9b6a50 261 msg_Usage "$0 {start|stop|status|restart|reload|init}"
53a28f77 262 exit 1
83fddc12 263 ;;
53a28f77 264esac
40c36bca 265
ee9b6a50 266exit $RETVAL
This page took 0.060471 seconds and 4 git commands to generate.