通过菜单一键安装mysql

Posted 明明叨叨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过菜单一键安装mysql相关的知识,希望对你有一定的参考价值。

#!/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的主要内容,如果未能解决你的问题,请参考以下文章

一键安装MySQL

打印选择菜单,一键安装Web服务

将MySQL集成打包成安装程序,实现一键安装

shell脚本一键安装LNMP菜单方式安装

LNMP(nginx+mysql+php)环境/架构 一键安装脚本

一键安装MySQL 主从复制SHELL脚本