3 # mysql A very fast and reliable SQL database engine
5 # chkconfig: 2345 90 90
7 # description: A very fast and reliable SQL database engine.
9 # pidfile: /var/state/mysql/mysqld.pid
11 # Source function library
12 . /etc/rc.d/init.d/functions
15 . /etc/sysconfig/network
17 MYSQL_DATA_DIR=/var/state/mysql
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
28 # Check that networking is up.
29 if [ "${NETWORKING}" = "no" ]; then
30 echo "WARNING: Networking is down. Mysql service can't be runed."
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."
41 if [ ! -f /var/lock/subsys/mysql ]; then
45 /usr/sbin/mysqld -u $MYSQL_USER --datadir=$MYSQL_DATA_DIR >>/var/log/mysql.log 2>&1 &
48 touch /var/lock/subsys/mysql
50 echo "Mysql already is running"
54 show Stopping mysql service
57 rm -f /var/state/mysql/mysqld.pid
58 rm -f /var/lock/subsys/mysql
68 # Check if not exist init database
69 if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
70 show Creating privilege mysql tables
73 hostname=`hostname` # Install this too in the user table
75 # Check if hostname is valid
76 resolved=`/usr/bin/resolveip $hostname 2>&1`
78 resolved=`/usr/bin/resolveip localhost 2>&1`
82 echo "Sorry, the host '$hostname' could not be looked up."
83 echo "Please configure the 'hostname' command to return a correct hostname."
88 # Create database directories mysql & test
89 if test ! -d $MYSQL_DATA_DIR/mysql; then
90 install -d -m700 -o #MYSQL_USER $MYSQL_DATA_DIR/mysql;
93 #mysqld --bootstrap need whole (and only one) sql command in one line
95 create_db="$create_db CREATE TABLE db ( "
96 create_db="$create_db Host char(60) DEFAULT '' NOT NULL, "
97 create_db="$create_db Db char(32) DEFAULT '' NOT NULL,"
98 create_db="$create_db User char(16) DEFAULT '' NOT NULL, "
99 create_db="$create_db Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
100 create_db="$create_db Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
101 create_db="$create_db Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
102 create_db="$create_db Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
103 create_db="$create_db Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
104 create_db="$create_db Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
105 create_db="$create_db Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
106 create_db="$create_db References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
107 create_db="$create_db Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
108 create_db="$create_db Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
109 create_db="$create_db PRIMARY KEY Host (Host,Db,User), "
110 create_db="$create_db KEY User (User)"
111 create_db="$create_db );"
114 create_host="$create_host CREATE TABLE host ( "
115 create_host="$create_host Host char(60) DEFAULT '' NOT NULL, "
116 create_host="$create_host Db char(32) DEFAULT '' NOT NULL, "
117 create_host="$create_host Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
118 create_host="$create_host Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
119 create_host="$create_host Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
120 create_host="$create_host Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
121 create_host="$create_host Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
122 create_host="$create_host Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
123 create_host="$create_host Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
124 create_host="$create_host References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
125 create_host="$create_host Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
126 create_host="$create_host Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
127 create_host="$create_host PRIMARY KEY Host (Host,Db)"
128 create_host="$create_host );"
131 create_user="$create_user CREATE TABLE user ("
132 create_user="$create_user Host char(60) DEFAULT '' NOT NULL, "
133 create_user="$create_user User char(16) DEFAULT '' NOT NULL, "
134 create_user="$create_user Password char(16) DEFAULT '' NOT NULL, "
135 create_user="$create_user Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
136 create_user="$create_user Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
137 create_user="$create_user Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
138 create_user="$create_user Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
139 create_user="$create_user Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
140 create_user="$create_user Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
141 create_user="$create_user Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
142 create_user="$create_user Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
143 create_user="$create_user Process_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
144 create_user="$create_user File_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
145 create_user="$create_user Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
146 create_user="$create_user References_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
147 create_user="$create_user Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
148 create_user="$create_user Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, "
149 create_user="$create_user PRIMARY KEY Host (Host,User)"
150 create_user="$create_user );"
153 create_func="$create_func CREATE TABLE func ( "
154 create_func="$create_func name char(64) DEFAULT '' NOT NULL, "
155 create_func="$create_func ret tinyint(1) DEFAULT '0' NOT NULL,"
156 create_func="$create_func dl char(128) DEFAULT '' NOT NULL, "
157 create_func="$create_func type enum ('function','aggregate') NOT NULL, "
158 create_func="$create_func PRIMARY KEY (name)"
159 create_func="$create_func ); "
162 create_tblpriv="$create_tblpriv CREATE TABLE tables_priv ( "
163 create_tblpriv="$create_tblpriv Host char(60) DEFAULT '' NOT NULL, "
164 create_tblpriv="$create_tblpriv Db char(60) DEFAULT '' NOT NULL, "
165 create_tblpriv="$create_tblpriv User char(16) DEFAULT '' NOT NULL,"
166 create_tblpriv="$create_tblpriv Table_name char(60) DEFAULT '' NOT NULL, "
167 create_tblpriv="$create_tblpriv Grantor char(77) DEFAULT '' NOT NULL, "
168 create_tblpriv="$create_tblpriv Timestamp timestamp(14), "
169 create_tblpriv="$create_tblpriv Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL, "
170 create_tblpriv="$create_tblpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
171 create_tblpriv="$create_tblpriv PRIMARY KEY (Host,Db,User,Table_name), "
172 create_tblpriv="$create_tblpriv KEY Grantor (Grantor)"
173 create_tblpriv="$create_tblpriv );"
176 create_colpriv="$create_colpriv CREATE TABLE columns_priv ( "
177 create_colpriv="$create_colpriv Host char(60) DEFAULT '' NOT NULL, "
178 create_colpriv="$create_colpriv Db char(60) DEFAULT '' NOT NULL, "
179 create_colpriv="$create_colpriv User char(16) DEFAULT '' NOT NULL, "
180 create_colpriv="$create_colpriv Table_name char(60) DEFAULT '' NOT NULL, "
181 create_colpriv="$create_colpriv Column_name char(60) DEFAULT '' NOT NULL, "
182 create_colpriv="$create_colpriv Timestamp timestamp(14), "
183 create_colpriv="$create_colpriv Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, "
184 create_colpriv="$create_colpriv PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
185 create_colpriv="$create_colpriv );"
187 if /usr/sbin/mysqld --bootstrap --skip-grant-tables \
188 --basedir=/usr --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA
199 INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
200 INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
201 INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
202 INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
203 REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
204 REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
205 INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
206 INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
212 echo " PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !"
213 echo " This is done with:"
214 echo " /usr/bin/mysqladmin -u root password 'new-password'"
215 echo " See the manual for more instructions."
220 echo " Installation of grant tables failed!"
222 echo " Examine the logs in $MYSQL_DATA_DIR for more information."
223 echo " You can also try to start the mysqld demon with:"
224 echo " /usr/sbin/mysqld --skip-grant &"
225 echo " You can use the command line tool"
226 echo " /usr/bin/mysql to connect to the mysql"
227 echo " database and look at the grant tables:"
229 echo "shell> /usr/bin/mysql -u root mysql"
230 echo "mysql> show tables"
232 echo "Try 'mysqld --help' if you have problems with paths. Using --log"
233 echo "gives you a log in $MYSQL_DATA_DIR that may be helpful."
235 echo "The latest information about MySQL is available on the web at"
236 echo "http://www.mysql.com"
237 echo "Please consult the MySQL manual section: 'Problems running mysql_install_db',"
238 echo "and the manual section that describes problems on your OS."
239 echo "Another information source is the MySQL email archive."
240 echo "Please check all of the above before mailing us!"
241 echo "And if you do mail us, you MUST use the /usr/bin/mysqlbug script!"
245 echo "Semms that database is initialized now. Remove by hand $MYSQL_DATA_DIR/mysql"
246 echo "before initialize database.".
250 echo "Usage: mysql {start|stop|status|restart|reload|init}"