Install MySQL from the menu with one click

Source: Internet
Author: User

#!/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 do 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'll be is 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 $

Done

Install MySQL from the menu with one click

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.