MySQL Automation installation Script

Source: Internet
Author: User

After studying the two-week Linux shell script, I finally wrote out a MySQL automation installation script. Plus today's full-day test, you can perform the installation of MySQL 5.5.40 normally. Other versions have not yet been tested. Now share. Also please expert guidance. The script is executed with the following prerequisites:

Environment Introduction:

1, Redhat 6.3 x64, minimized installation

2, ram:2g,hd:30g

3. Turn off SELinux

4. Configure the Yum source (I use my own configured source)

5, open ssh, sick configuration good iptables, allow remote login access.

6. Required Software and documents:

Cmake-2.8.10.1.tar.gz

Bison-3.0.tar.gz

Zlib-1.2.7.tar.gz

Mysql-5.5.40.tar.gz

MY.CNF//teacher-shared files


Script content:

#!/bin/bash


echo "Step One:create folder and Mount packages"


if [-d/mnt/share]

Then

echo "Find It,don ' t need to create it."


Else

Mkdir-p/mnt/share

if [[$ = 0]]

Then

echo "Create it successfully!"

Else

echo "Can ' t create this folder!pls check out!"

Fi

Mount-t Cifs-o username=swen02,password=autozhao01! 172.16.11.20/lamp-all-software/mnt/share

Fi


echo "Step two:create mysql Installation path"


if [-d/project/class2]

Then

echo "Find it, don t need to create it."

Else

Mkdir-p/project/class2/

if [[$ = 0]]

Then

echo "Create it successfully!"

Else

echo "Can ' t create this floder!pls check out!"

Fi

Fi


echo "Step three:copy packages to the folder"


cp/mnt/share/cmake-2.8.10.1.tar.gz/project/class2/

cp/mnt/share/bison-3.0.tar.gz/project/class2/

cp/mnt/share/zlib-1.2.7.tar.gz/project/class2/

cp/mnt/share/mysql-5.5.40.tar.gz/project/class2/

cp/mnt/share/my.cnf/project/class2/


echo "Step Four:install Base Packages"


Yum-y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*


Cd/project/class2

TAR-XZVF cmake-2.8.10.1.tar.gz

CD cmake-2.8.10.1

./bootstrap

Make && make install

if [[$ = 0]]

Then

echo "Good job!"

Else

echo "Sorry, pls check out!"

Exit 1

Fi

Cd..

TAR-ZXVF bison-3.0.tar.gz

CD bison-3.0

./configure

Make && make install

if [[$ = 0]]

Then

echo "Good job!"

Else

echo "Sorry, pls check out!"

Exit 1

Fi

Cd..

TAR-ZXVF zlib-1.2.7.tar.gz

CD zlib-1.2.7

./configure

Make && make install

Cd..

if [[$ = 0]]

Then

echo "Good job!"

Else

echo "Sorry, pls check out!"

Exit 1

Fi



echo "Step five:configure system Referenc"


flags= "-o3-g-fno-exceptions-static-libgcc-fno-omit-frame-pointer-fno-strict-aliasing"

cxx=g++

cxxflags= "-o3-g-fno-exceptions-fno-rtti-static-libgcc-fno-omit-frame-pointer-fno-strict-aliasing"

Export CFLAGS CXX cxxflags


echo "Step six:begin to install MySQL"


Groupadd MySQL

Useradd-r-G MySQL MySQL

TAR-ZXVF mysql-5.5.40.tar.gz

CD mysql-5.5.40

Cmake-dcmake_install_prefix=/project/class2/mysql

Make

Make install

if [[$ = 0]]

Then

echo "Good job!"

Else

echo "Sorry, pls check out!"

Exit 1

Fi

Cd..


#create folder and initial new db

mkdir./mysql/run

mkdir./mysql/log

Chown-r Mysql.mysql/project/class2/mysql

rm-rf/project/class2/mysql/data/*

./mysql/scripts/mysql_install_db--datadir=/project/class2/mysql/data--user=mysql--basedir=/project/class2/ Mysql


#modify my.cnf and copy new one


Sed ' s/default-character-set=gbk/default-character-set=utf8/' my.cnf | Sed ' s/skip-ssl/#skip-ssl/' >./mysql/my.cnf

Chown-r mysql.mysql/project/class2/mysql/my.cnf


#creat Ln


Ln-s/project/class2/mysql/run/mysql.sock/tmp/mysql.sock


Mv/root/.bash_profile/root/.bash_profile.bak


/bin/sed '/export path/i\export path= "$PATH":/project/class2/mysql/bin/'/root/.bash_profile.bak >/root/.bash_ Profile


#start MySQL Service

./mysql/bin/mysqld_safe--DEFAULTS-FILE=/PROJECT/CLASS2/MYSQL/MY.CNF &


#waitting for service to being started

Signal=0

while [["$signal" = 0]]

Do

If [-Z "' grep ' Source distribution '/project/class2/mysql/log/alert.log '"]

Then

echo "Not found it"

Sleep 30

Else

echo "Found it"

Let Signal+=1

Fi

Done


#logout and Relogin, new PATH would be a take effect.

Kill-9 $PPID



MySQL Automation installation Script

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.