#!/bin/bash
echo "下载MySQL源安装包"
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
echo "安装MySQL源"
yum -y install mysql57-community-release-el7-11.noarch.rpm
echo "查看一下安装效果"
yum repolist enabled | grep mysql.*
echo "安装MySQL服务器中途需要手动输入两次Y"
yum install mysql-community-server
echo "安装完毕"
read -p "请问您是否需要启动MySQL服务(Y/N):" yes
if [ $yes == Y ] || [ $yes == N ]
then
systemctl start mysqld.service
if [ $? == 0 ];
then
echo "MySQL启动成功"
echo "查看MySQL状态是否正常"
systemctl status mysqld.service | grep running
if [ $? == 0 ]
then
echo "MySQL服务状态正常!"
echo -e "获取随机密码"
suiji=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $11}')
echo "你的随机密码为:$suiji"
echo "准备修改my.cnf配置文件"
echo -e "plugin-load=validate_password.so \nvalidate-password=OFF \nskip-grant-tables" >> /etc/my.cnf
echo "进行重启mysql服务配置文件生效"
systemctl restart mysqld
read -p '请问您是否需要重新设置密码(Y/N):' yy
if [ $yy == Y ] || [ $yy == N ]
then
read -p "输入你想设置的密码:" pw
mysql -uroot -p$suiji -e "set password=password('$pw');" >> /dev/null 2>&1
echo "密码设置成功!"
else
echo "那你就用随机的密码进行登录即可!"
fi
else
echo "MySQL服务状态异常!"
fi
else
echo "MySQL启动失败"
fi
else
echo "MySQL不启动"
fi