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