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