Linux mysql boot automatically start 3 methods

  
                  Booting is mainly to add the startup command to the Linux startup service, you can achieve it, specifically for you to organize two pieces of code.

The first kind of manual can be added simply to start mysql automatically, followed by a piece of shell code that has nothing to do.

mysql is set to linux service
Code is as follows

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 is a simple startup script v0.1 mysqldauto
The code is as follows $vi mysqldauto #!/Bin/sh # Version: 0.1 by [email protected] /opt/mysql/bin/mysqld_safe --user=mysql & #This needs to be changed to your mysqld_safe directory $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 in /etc/Rc.d/rc3.d/below (note that the link is used here), mysqld can be started automatically.

Startup script
Code is as follows

#!/bin/sh ########################################### ####################Created by teddylu at 2012-12-12 #Used for mysql start,stop,restart ########### ###################################################################################### "root" mysql_pwd="" CmdPath="/usr/local/mysql/bin"

#startup function function_start_mysql() { printf "Starting MySQL...\ " /bin/Sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null & }

#stop function function_stop_mysql() { printf "Stoping MySQL...\ " ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown }

#restart function function_restart_mysql() { printf "Restarting MySQL...\ " function_stop_mysql sleep 2 function_s Tart_mysql }

case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/${port}/mysql {start

Copyright © Windows knowledge All Rights Reserved