Rehat一键安装mysql脚本和备份数据库脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rehat一键安装mysql脚本和备份数据库脚本相关的知识,希望对你有一定的参考价值。
Rehat一键安装mysql脚本
##说明:适用,Rehat 5 6 7
1.运行状态,运行成功输出mysql临时密码
2.代码如下
#!/bin/bash #获取系统信息 sudo cat /etc/issue>myfile aa=sudo grep ‘5.‘ myfile bb=sudo grep ‘6.‘ myfile cc=sudo grep ‘7.‘ myfile echo $aa echo "It is a test" > myfile #获取系统信息 sudo cat /etc/issue>myfile aa=sudo grep ‘5.‘ myfile bb=sudo grep ‘6.‘ myfile cc=sudo grep ‘7.‘ myfile echo $aa echo $cc echo $bb #配置yum源 if [ "$aa"x != "‘‘"x ] then echo "您的系统是rehat5的版本,即将为您安装mysql" wget https://repo.mysql.com//mysql57-community-release-el5-8.noarch.rpm --no-check-certificate rpm -Uvh mysql57-community-release-el5-8.noarch.rpm elif [ "$bb"x != "‘‘"x ] then echo "您的系统是rehat6的版本,即将为您安装mysql" wget https://repo.mysql.com//mysql57-community-release-el6-10.noarch.rpm --no-check-certificate rpm -Uvh mysql57-community-release-el6-10.noarch.rpm elif [ "$cc"x != "‘‘"x ] then echo "您的系统是rehat7的版本,即将为您安装mysql" wget https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm --no-check-certificate rpm -Uvh mysql57-community-release-el7-10.noarch.rpm fi #安装系统 yum install mysql-community-server #启动服务 service mysqld start #查看临时密码文件 grep ‘temporary password‘ /var/log/mysqld.log
Rehat备份mysql脚本
1.代码如下:
#!/bin/bash #保存备份个数 number=3 #备份保存路径 backup_dir=/root/mysqlbackup #日期 dd=`date +%Y%m%d` #备份工具 tool=mysqldump #用户名 username=root #密码 password=****** #将要备份的数据库 database_name=users #简单写法 mysqldump -u root -p123456 users > /root/mysqlbackup/users-$filename.dump $tool -u $username -p$password $database_name > $backup_dir/$database_name-$dd.dump #写创建备份日志 echo "create $backup_dir/$database_name-$dd.dupm" >> $backup_dir/log.txt #找出需要删除的备份 delfile=`ls -l -crt $backup_dir/*.dump | awk ‘{print $9 }‘ | head -1` #判断现在的备份数量是否大于$number count=`ls -l -crt $backup_dir/*.dupm | awk ‘{print $9 }‘ | wc -l` if [ $count -gt $number ] then rm $delfile #删除最早生成的备份,只保留number数量的备份 #写删除文件日志 echo "delete $delfile" >> $backup_dir/log.txt fi
以上是关于Rehat一键安装mysql脚本和备份数据库脚本的主要内容,如果未能解决你的问题,请参考以下文章