mysql自动安装脚本

前端之家收集整理的这篇文章主要介绍了mysql自动安装脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash
#filename: install_MysqL.sh
#function: use rpm package install MysqL

#安装MysqL的rpm包
MysqL_instpkg1="MysqL-server-5.0.16-0.i386.rpm"
MysqL_instpkg2="MysqL-client-5.0.16-0.i386.rpm"

#安装日志文件
MysqL_instlog="install_MysqL.log"
MysqL_instlog="`pwd`"/"$MysqL_instlog"

#参数检查
if [ "$#" -gt "1" ];then
	echo "usage: ./install_MysqL [dir_instpkg]" | tee $MysqL_instlog
	exit 1
elif [ "$#" -eq "1" ];then
	dir_instpkg="$1"
	if [ ! -d "$dir_instpkg" ];then
		echo "$dir_instpkg is not a dirctory" | tee $MysqL_instlog
		exit 1
	fi
else
	dir_instpkg="`pwd`"
fi

#检查系统是否已经安装了MysqL
rpm -qa | grep 'MysqL'
if [ $? == 0 ];then
	echo "MysqL is installed" | tee $MysqL_instlog
	exit 1
fi

dir_inst="/usr/MysqL"
mkdir $dir_inst
cp $dir_instpkg/$MysqL_instpkg1 $dir_inst
if [ $? != 0 ];then
	echo "cp $dir_instpkg/$MysqL_instpkg1 $dir_inst is fail" | tee $MysqL_instlog
	exit 1
fi

cp $dir_instpkg/$MysqL_instpkg2 $dir_inst
if [ $? != 0 ];then
    echo "cp $dir_instpkg/$MysqL_instpkg2 $dir_inst is fail" | tee $MysqL_instlog
	exit 1
fi  
		  
cd $dir_inst
rpm -ivh $MysqL_instpkg1 && rpm -ivh $MysqL_instpkg2

#检查安装成功否
rpm -qa | grep 'MysqL'
if [ $? != 0 ];then
	echo "MysqL install fail" | tee $MysqL_instlog
	exit 1
else
	echo "MysqL isntall success" | tee $MysqL_instlog
fi

#启动MysqL
#/etc/rc.d/init.d/MysqL start
service MysqL start
if [  $? == 0 ];then
	echo "start MysqL is success" | tee $MysqL_instlog
else
	echo "start MysqL is fail" | tee $MysqL_instlog
fi

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章