Home > Database > Mysql Tutorial > body text

Create a script to implement automatic backup of mysql

王林
Release: 2020-01-28 21:50:19
forward
1998 people have browsed it

Create a script to implement automatic backup of mysql

First execute the vi dbbackup.sh command, enter in the open editor:

#!/bin/bash
/usr/local/mysql/bin/mysqldump -uuser -ppasswd databasename > /home/wwwroot/backup/date_$(date'+%Y%m%d').sql
Copy after login

The meaning of this command is: use mysqldump to export the database named databasename to /home/wwwroot/backup/ folder and name it date_date.sql, -u is followed by your Mysql user name, -p is followed by the Mysql password, databasename is the name of the database to be backed up, replace these three Become your own.

Recommended related article tutorials: mysql video tutorial

Then modify the permissions and execute the backup script to see if the backup is successful:

chmod +x dbbackup.shsh dbbackup.sh
Copy after login

If everything is checked and OK If you have a problem, just create a scheduled task to automatically back up your data. Enter the command:

crontab -e
Copy after login

Then enter the scheduled task in the open file:

56 23 * * * /root/dbbackup.sh
Copy after login

Finally, press the esc key and enter: wq to exit editing. and save the file.

Okay, the scheduled task is created, and dbbackup.sh is executed to back up the database at 23:56 every day.

Recommended related articles and tutorials: mysql tutorial

The above is the detailed content of Create a script to implement automatic backup of mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!