In fact, the MySQL automatic backup of the small script is very simple, the following is the steps of this small script.
The code is as follows |
Copy Code |
#cd/www #mkdir Mysqlbackup #vi mysqlautobackup.sh
|
This mysqlautobackup.sh file is written in the following sections:
The code is as follows |
Copy Code |
Filename= ' Date +%y%m%d ' Mysql_bin_dir/mysqldump--opt datename-u Dateuser-pdatepassword | gzip >/www/mysqlbackup/datename$filename.gz
|
Save the exit, and then give the file the executable permission:
The code is as follows |
Copy Code |
#chmod 777 mysqlautobackup.sh |
Then edit crontab:
The code is as follows |
Copy Code |
#vi/etc/crontab
|
On the last line, add the following:
The code is as follows |
Copy Code |
5 * * * root/www/mysqlautobackup.sh
|
and restart the crontab:
The code is as follows |
Copy Code |
#/etc/rc.d/init.d/crond Restart
|
This is done, and every day in the morning 5 points will automatically perform a MySQL automatic backup command.
Note: Mysql_bin_dir refers to MySQL's bin path. Datename refers to the database name. Dateuser refers to the database user name. Datepassword refers to the database user password.
This is the Linux under the implementation of automatic backup of MySQL tips, is it easy?
Pay attention.
Note:
MySQL is running as a MySQL user and will fail to write to/home/mybackup
chmod 777/home/mybackup
This is a privilege issue in Linux, and you don't have to think about it if you can successfully back it up.