栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

centos7下mysql的安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

centos7下mysql的安装

#!/bin/bash

#
#本脚本适用于centos7的mysql-5.7.37版本
#author:teachain
#date:2022-04-29
#email:281477138@qq.com

#从https://mirrors.ustc.edu.cn/mysql-ftp/Downloads下载文件
#mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar 


user="root"

password="123456"

if command -v mysql >/dev/null 2>&1;then
  echo "mysql is installed"
  exit 0
fi

rm -rf /etc/my.cnf.rpmsave

rm -rf /etc/my.cnf.rpmnew

rm -rf /etc/my.conf

rm -rf /var/lib/mysql

rm -rf /var/lib/yum/history/*.sqlite

rm -rf /var/log/mysqld.log

yum install -y mysql-community-*

echo "mysqld is starting,please wait......"

systemctl start mysqld

systemctl status mysqld

temporaryPassword=$(grep 'temporary password' /var/log/mysqld.log|awk '{print $11}')

if [ $temporaryPassword == "" ];then
   echo "temporary password not in /var/log/mysqld.log"
   exit 1
fi  

sql="set global validate_password_policy=LOW;"

mysql  --connect-expired-password -u ${user} -p${temporaryPassword} -e "${sql}"


sql="set global validate_password_length=6;"

mysql  --connect-expired-password -u ${user} -p${temporaryPassword} -e "${sql}"


sql="ALTER USER '${user}'@'localhost' IDENTIFIED BY '${password}';use mysql;update user set Host='%' where User='${user}';flush privileges;"

mysql  --connect-expired-password -u ${user} -p${temporaryPassword} -e "${sql}"

if [ -f "/etc/my.cnf" ];then

tee -a /etc/my.cnf < 

卸载mysql

if command -v mysql >/dev/null 2>&1;then
   list=$(yum list installed | grep mysql|awk '{print $1}')
   for i in $list;
   do
      systemctl stop mysql
      echo "compontent:$i"
      yum -y remove $i
   done
else
   echo "mysql is not installed"
   exit 0
fi

rm -rf /var/lib/mysql

rm -rf /var/lib/yum/history/*.sqlite

rm -rf /var/log/mysqld.log

rm -rf /etc/my.cnf.rpmsave

rm -rf /etc/my.cnf.rpmnew

rm -rf /etc/my.conf

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/844315.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号