Rehat install MySQL script in one click
# #说明: Applicable, Rehat 5 6 7
1. Running status, running successfully output MySQL temporary password
2. The code is as follows
#!/bin/Bash #获取系统信息sudo Cat/etc/issue>MYFILEAA=sudo grep '5.'Myfilebb=sudo grep '6.'myfilecc=sudo grep '7.'myfileEcho$aaEcho "It is a test">myfile# getting System Informationsudo Cat/etc/issue>MYFILEAA=sudo grep '5.'Myfilebb=sudo grep '6.'myfilecc=sudo grep '7.'myfileEcho$aaEcho$ccEcho$BB # Configuring the Yum sourceif["$aa"X! =""'"x] Then Echo "your system is a REHAT5 version that will install MySQL for you" wgetHttps//repo.mysql.com//mysql57-community-release-el5-8.noarch.rpm--no-check-certificaterpm-UVH mysql57-community-release-el5-8. noarch.rpmelif["$BB"X! =""'"x] Then Echo "your system is a REHAT6 version that will install MySQL for you" wgetHttps//repo.mysql.com//mysql57-community-release-el6-10.noarch.rpm--no-check-certificaterpm-UVH mysql57-community-release-el6-Ten. noarch.rpmelif["$CC"X! =""'"x] Then Echo "your system is a REHAT7 version that will install MySQL for you" wgetHttps//repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm--no-check-certificaterpm-UVH mysql57-community-release-el7-Ten. noarch.rpmfi#安装系统Yum Installmysql-community-server# Start service mysqld start# View temporary password filegrep 'Temporary password'/var/log/mysqld.log
Rehat backup MySQL Script
1. The code is as follows:
#!/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 #删除最早生成的备份, keep only the number of backups #写删除文件日志 echo "Delete $delfile" >> $backup _dir/log.txt fi
Rehat install MySQL script and backup database script in one click