码迷,mamicode.com
首页 > 数据库 > 详细

通过菜单一键安装mysql

时间:2017-04-11 11:05:39      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:war   .gz   x86_64   case   echo   files   chm   tar.gz   chmod   

#!/bin/bash

#create by steven

#create date 2017/04/07

###########define variable

. /etc/init.d/functions

version="mysql-5.5.54-linux2.6-x86_64" #mysql software version

install_path=/application/mysql-5.5.54 #mysql install path

password="123456" #defualt mysql root password

resource=/software #mysql tar file

linkdir=/application/mysql #mysql link folder

datadir=/application/mysql/data #mysql data file folder

#####function

function menu(){

echo ‘

====MySQL Auto install====

1.Prepare to install mysql

==========================

2.Install MySQL

==========================

3 Start MySQL

==========================

4.Stop MySQL

==========================

5. Exit

==========================

‘‘‘

read -t 10 -p "Pls input the number what you want:" num

}

pre_install(){

mkdir -p "$datadir"

cd $resource

tar -xf "$version.tar.gz"

ln -s $install_path $linkdir

cd $resource/$version

mv * $linkdir/

useradd mysql -s /sbin/nologin -M >>/tmp/mysql_install_log

echo "$password"|passwd --stdin mysql >>/tmp/mysql_install_log

chown -R mysql.mysql "$linkdir"

}

install(){

"$linkdir"/scripts/mysql_install_db --basedir=$linkdir --datadir=$datadir --user=mysql &>/dev/null

cp $linkdir/support-files/mysql.server /etc/init.d/mysqld

cp $linkdir/support-files/my-small.cnf /etc/my.cnf

chmod +x /etc/init.d/mysqld

/bin/sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

}

start(){

/etc/init.d/mysqld start

}

stop(){

/etc/init.d/mysqld stop

}

exit(){

exit 0

}

main(){

menu

case $num in

1)

pre_install

if [ $? -eq 0 ]

then

echo "pre_install succceed"

else

echo "pre_install failed"

fi

;;

2)

install

if [ $? -eq 0 ]

then

echo "install succceed"

else

echo "install failed"

fi

;;

3)

echo "This action need few seconds"

start

if [ $? -eq 0 ]

then

echo "MySQL start succceed"

else

echo "MYSQL start failed"

fi

;;

4)

stop

if [ $? -eq 0 ]

then

echo "MySQL stop succceed"

else

echo "MySQL stop failed"

fi

;;

5)

echo "you will be out in 2 seconds"

sleep 2

exit 0

;;

*)

[ "$num" -ne "1" -o "$num" -ne "2" -o "$num" -ne "3" -o "$num" -ne "4" -o "$num" -ne "5" ]&&echo "Usage should be $0:{1|2|3|4|5}"

esac

}

########Begin execute

while true

do

main $1

done

通过菜单一键安装mysql

标签:war   .gz   x86_64   case   echo   files   chm   tar.gz   chmod   

原文地址:http://www.cnblogs.com/dianzixiaoming/p/6692582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!