標籤:mysql navicat sqlyog backup shell
1.對mysql資料庫的操作,在更改設定檔、增刪改查資料之前,先做好全庫指令碼匯出備份以及物理檔案匯出的工作,以防操作出錯。如果操作出錯,可以很快復原資料庫到最初狀態。
2.設定複雜的root使用者密碼,並且進行正確的授權,並且flush privileges;進行重新整理許可權。如果root密碼丟失,可以修改root使用者的mysql密碼。但是資料庫會要求重啟。
3.選擇好mysql的用戶端串連工具,比如navicat或者SQL Yog。
4.設定好正確的備份策略,以及備份指令碼,指令碼如下:
[[email protected]]# more mysqlfull.sh
#!/bin/sh
# Name:mysqlFullBackup.sh
# PS:MySQL DataBase Full Backup.
# Use mysqldump --help get more detail.
scriptsDir=`pwd`
mysqlDir=/var/lib/mysql
user=root
userPWD=XXXXXX
dataBackupDir=/usr/local/sdc/backup/mysqlbackup
eMailFile=$dataBackupDir/email.txt
[email protected]
logFile=$dataBackupDir/mysqlbackup.log
DATE=`date -I`
echo "" > $eMailFile
echo $(date +"%y-%m-%d %H:%M:%S")>>$eMailFile
cd $dataBackupDir
dumpFile=mysql_$DATE.sql
GZDumpFile=mysql_$DATE.sql.tar.gz
#mysqldump -u$user -p$userPWD --opt--default-character-set=utf8 --extended-insert=false --triggers -R --hex-blob--all-databases --flush-logs --delete-master-logs --delete-master-logs -x >$dumpFile
mysqldump -u$user -p$userPWD--all-databases > $dumpFile
#if [[ $? == 0 ]]
if [ "$?" = "0" ]
then
tar czf $GZDumpFile $dumpFile >> $eMailFile 2>&1
echo "BackupFileName:$GZDumpFile" >> $eMailFile
echo "DataBase Backup Success!" >> $eMailFile
rm -f $dumpFile
# Delete daily backup files.
# cd $dataBackupDir/daily
# rm -f *
# Delete old backup files(mtime>2).
#$scriptsDir/rmBackup.sh
find $dataBackupDir -type f -mtime +33 -execrm {} \;
# Move Backup Files To Backup Server.
# if (( !$? )); then
# echo "Move Backup Files To Backup Server Success!" >>$eMailFile
# else
# echo "Move Backup Files To Backup Server Fail!" >>$eMailFile
# fi
else
echo "DataBase Backup Fail!">> $emailFile
fi
echo"--------------------------------------------------------" >>$logFile
cat $eMailFile >> $logFile
#cat $eMailFile | mail -s "MySQLBackup" $eMail
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/B0/wKioL1Ppo5PjszMxAAaXu3084OU213.jpg" title="MYSQL串連情況.jpg" alt="wKioL1Ppo5PjszMxAAaXu3084OU213.jpg" />
本文出自 “林夕” 部落格,請務必保留此出處http://lutaoxu.blog.51cto.com/4224602/1538943