加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

mysql自动安装脚本

发布时间:2020-12-15 07:07:44 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/bash#filename: install_mysql.sh#function: use rpm package install mysql#安装mysql的rpm包mysql_instpkg1="MySQL-server-5.0.16-0.i386.rp

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/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

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读