脚本
#!/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
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/101844.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...