通过shell脚本一键安装mysql服务

话不多说直接上脚本,将脚本移动到空文件夹,运行脚本然后等待十分钟左右

#!/bin/bash
#author:gz
#date:2022-7-30
#action:install_mysql
rpm -qa | grep  mariadb
if [  $? != 0 ]
then
        echo "没有mariadb包"
else
        rpm -e mariadb-5.5.68-1.el7.x86_64
        rpm -e mariadb-libs-5.5.68-1.el7.x86_64
        echo "正在卸载mariadb"
        echo "正在安装mysql"
fi
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
tar -xf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
yum localinstall * -y
systemctl start mysqld
if [ $? -eq  0 ]
then
        echo "安装成功"
else
        echo "安装失败"
fi
oldpasswd=`grep "password" /var/log/mysqld.log  | awk '{print $NF}'`
read -p "请输入mysql新密码:" newpasswd
mysqladmin -uroot -p$oldpasswd password $newpasswd
echo "密码修改成功"
 

你可能感兴趣的:(linux,运维)