Home >Database >Mysql Tutorial >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
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
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
Then enter the scheduled task in the open file:
56 23 * * * /root/dbbackup.sh
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!