#!/bin/bashusername=roothostname=localhostpassword=rootmysql-u$username-h$hostname-p$password-e "Show Databases" Read-p "PLZ input a dbname:" dbnameread-p "PLZ input backupdir:" backupdirread-p "PLZ input backupname:" BackupName if [["$dbname" = = "Quit" | | "$backupdir" = = "Quit" | | "$backupname" = = "Quit"]];then Exit 4 else echo "----------Backup start----------"! [-D $backupdir] && mkdir-p $backupdir if [["$dbname" = = "All"]];then/usr/local/mysql/bin/mysqldump -u$username-h$hostname-p$password--all-databases--lock-all-tables--flush-logs--master-data=2 >> $backupdir /$backupname Else/usr/local/mysql/bin/mysqldump-u$username-h$hostname-p$password--databases $dbname--lock-a Ll-tables--flush-logs--master-data=2 >> $backupdir/$backupname fi if [$?-eq 0];then echo------ ---backup OK-------"echo"---------backup stop-------"Else echo"-------back lose--------"exitFi fi
When using scripts, you need to modify the database information within the script to give execute permissions.
A script to manually back up the MySQL database