When I was operating the database today, I accidentally deleted the data of a table, which made the data unrecoverable. I suddenly realized the importance of data backup.
I am using the version of MySQL 5.6
1. Create a directory for backup storage
#mkdir /home/backup
2. Write the .sh script file to be executed
#vim /home/backup/mybackup.sh
Write the following content in
#!/bin/bash
mysqldump DATABASE_NAME > /home/backup/DATABASE_NAME_$(date+%Y%m%d_%H%M%S).sql
3. Authorize the script file
#chomd +x /home/backup/mybackup.sh
4. Modify the mysql configuration file
#vim /etc/my.cnf
Look for the existence of the [mysqldump] configuration group in it. If it does not exist, add this group, and then enter the following information under it
user=root passowrd=your database password
Save and exit, restart the mysql service
5. Whether the test script can be executed
#cd /home/backup
#./mybackup.sh
If no error is reported, it means that it can be executed normally. The next step is to add the script to the scheduled task.
6. Add timed tasks
#crontab -e
Enter the following in the editing interface
00 4 * * * /home/backup/mybackup.sh
save and exit
Console output: crontab: installing new crontab timed task added successfully