练习使用shell在阿里云安装MySQL
#!/bin/bash #阿里云初始安装MySQL #step1:查寻MariaDB 并卸载 MariaDB_filename=`rpm -qa|grep mariadb` if [ -d "$MariaDB_filename" ] then echo "存在文件名为$MariaDB_filename" rpm -e --nodeps $MariaDB_filename else echo "没有该文件" fi cd ~ #step2:搭建MySQL wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm if [ $? -eq 0 ] then echo "下载完成" yum -y install mysql57-community-release-el7-10.noarch.rpm if [ $? -eq 0 ] then echo "安装完成" yum -y install mysql-community-server if [ $? -eq 0 ] then echo "安装server完成" systemctl start mysql.service if [ $? -eq 0 ] then echo "mysqlserver安装成功!" else echo "出错了!" echo $? 2>>/root/error.txt fi else echo "server 安装出错了" echo $? 2>>/root/error.txt fi else: echo "安装出错了" fi else echo "下载出错了" echo $? 2>/root/error.txt fi