Home  >  Article  >  Database  >  Linux自动备份MySQL数据库实用方法_MySQL

Linux自动备份MySQL数据库实用方法_MySQL

PHP中文网
PHP中文网Original
2016-05-27 14:29:38924browse

/usr/bin为mysql安装目录 
建备份文件夹: 
mkdir mysql_data_bak 
建脚本文件: 
touch autobackupmysql.sh 
打开文件 
vi autobackupmysql.sh 
在脚本中加入如下内容: 
filename=`date +%Y%m%d` 
/usr/bin/mysqldump -opt mysql -u root -proot|gzip >/mysql_data_bak/name$filename.gz 
这里注意了 
一般的: 
********************************************************** 
打开自动执行文件 
vi /etc/crontab 
在etc中加入如下内容,让其自动执行任务。 
01 15 * * * root /mysql_data_bak/autobackupmysql 
********************************************************** 
Redhat方法: 
  Redhat的crontab采用按时间调用4个目录(/etc/cron.hourly:每小时;/etc/cron.daily:每 
天;/etc/cron.weekly:每周;/etc/cron.monthly:每月)中脚本出来运行的方式。 
  Redhat中只需要将刚才编辑的脚本复制到相应的目录即可。 
cp /mysql_data_bak/autobackupmysql etc/cron.daily 
重启etc 
/etc/rc.d/init.d/crond restart

 以上就是Linux自动备份MySQL数据库实用方法_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
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