The first type of manual simple to join can be implemented automatically start MySQL, behind is nothing to do write a section of the Shell code.
MySQL set to Linux service
The code is as follows |
Copy Code |
Cp/usr/local/mysql5/share/mysql/mysql.server/etc/init.d/mysqld Chkconfig--add mysqld Chkconfig--level 2345 mysqld on Chown Mysql:mysql-r/usr/local/mysql5/ Service mysqld Start |
Here's a simple startup script v0.1 Mysqldauto
The code is as follows |
Copy Code |
$vi Mysqldauto #!/bin/sh # version:0.1 by orczhou@gmail.com /opt/mysql/bin/mysqld_safe--user=mysql & #这里需要修改为你的mysqld_safe目录 $chmod +x Mysqldauto $MV mysqldauto/etc/rc.d/init.d/ $LN-S/etc/rc.d/init.d/mysqldauto/etc/rc.d/rc3.d/s99mysqld
|
So we put the created Mysqldauto script under the/etc/rc.d/rc3.d/(note the way link is used here), Mysqld can start automatically.
Startup script
The code is as follows |
Copy Code |
#!/bin/sh ################################################ #Created by Teddylu at 2012-12-12 #Used for MySQL Start,stop,restart ################################################ #init port=3306 Mysql_user= "Root" Mysql_pwd= "" Cmdpath= "/usr/local/mysql/bin" #startup function Function_start_mysql () { printf "Starting MySQL ... \ n " /bin/sh ${cmdpath}/mysqld_safe--defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null & } #stop function Function_stop_mysql () { printf "stoping MySQL ... \ n " ${cmdpath}/mysqladmin-u ${mysql_user}-p${mysql_pwd}-s/data/${port}/mysql.sock shutdown } #restart function Function_restart_mysql () { printf "Restarting MySQL ... \ n " Function_stop_mysql Sleep 2 Function_start_mysql } Case is in start Function_start_mysql ;; Stop) Function_stop_mysql ;; Restart) Function_restart_mysql ;; *) printf "Usage:/data/${port}/mysql {start|stop|restart}\n" Esac |