1.对mysql数据库的操作,在更改配置文件、增删改查数据之前,先做好全库脚本导出备份以及物理文件导出的工作,以防操作出错。如果操作出错,可以很快回滚数据库到最初状态。
2.设置复杂的root用户密码,并且进行正确的授权,并且flush privileges;进行刷新权限。如果root密码丢失,可以修改root用户的mysql密码。但是数据库会要求重启。
3.选择好mysql的客户端连接工具,比如navicat或者SQL Yog。
4.设置好正确的备份策略,以及备份脚本,脚本如下:
[root@localhostXXX]# 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=XXX@XXX.com
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
本文出自 “林夕” 博客,请务必保留此出处http://lutaoxu.blog.51cto.com/4224602/1538943
原文:http://lutaoxu.blog.51cto.com/4224602/1538943