Home > Database > Mysql Tutorial > linux下备份MYSQL数据库的方法_MySQL

linux下备份MYSQL数据库的方法_MySQL

WBOY
Release: 2016-06-01 13:19:59
Original
941 people have browsed it

bitsCN.com 只需按照下面3步做,一切都在你的掌控之下:
第一步:在服务器上配置备份目录代码:
--------------------------------------------------------------------------------
mkdir /var/lib/mysqlbackup
cd /var/lib/mysqlbackup
--------------------------------------------------------------------------------
第二步:编写备份脚本代码:
--------------------------------------------------------------------------------
vi dbbackup.sh
--------------------------------------------------------------------------------
粘帖以下代码,务必更改其中的username,password和dbname。
代码:
--------------------------------------------------------------------------------
#!/bin/sh #Username to access the MySQL server USERNAME="username" # Username to access the MySQL server PASSWORD="password" # List of DBNAMES for Backup DBNAME="dbname" #date timestamp for log message DATE=`/bin/date +%Y-%m-%d_%Hh%Mm` #output file OUTDIR="/var/lib/mysqlbackup/" OUTFILE="ip_bindass".$DATE."sql.gz" #working directory DIR="/var/lib/mysqlbackup/"#cd $DIR # MySQL Backup /usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE
--------------------------------------------------------------------------------
更改备份脚本权限
代码:
--------------------------------------------------------------------------------
chmod +x dbbackup.sh
--------------------------------------------------------------------------------
第三步:用crontab定时执行备份脚本代码:
--------------------------------------------------------------------------------
crontab -e
--------------------------------------------------------------------------------
若每天下午3点20备份,添加如下代码,
代码:
--------------------------------------------------------------------------------
20 15 * * * /var/lib/mysqlbackup/dbbackup.sh
--------------------------------------------------------------------------------
搞定!bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template