shell脚本一键yum安装mysql数据库

#!/bin/bash

#使用shell脚本来一键安装mysql库

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

[ -f /etc/yum.repos.d/mysql.repo ] || touch /etc/yum.repos.d/mysql.repo

cat >> /etc/yum.repos.d/mysql.repo << EOF
[mysql]
name=mysql
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.ustc.edu.cn/mysql-repo/RPM-GPG-KEY-mysql
EOF
if [ $? -eq 0 ]; then
	echo "已写入"
else
	echo "写入失败"
	exit 0

mysql_f=$(yum repolist enabled | grep mysql)
if [[ $mysql_f = "" ]]; then
	echo "失败了,请检查错误"
	exit 0
else
	echo "继续吧"

yum -y install mysql-community-server
if [ $? -eq 0 ]; then
	echo "安装成功"
else
	echo "安装失败"
	exit 0
fi

systemctl start mysqld
read -p "请输入数据库新密码:" mysql_password
if [ $? -eq 0 ]; then 
	frist_password=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')
	mysqladmin -uroot -p$frist_password password $mysql_password
else
	echo "失败了"
	exit 0
fi







该脚本用于安装mysql5.7数据库

猜你喜欢

转载自blog.csdn.net/XX_HK/article/details/134630460