3 ways to automatically start MySQL boot in Linux

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.