- Create a shell script
The content of the creation script is as follows:
/usr/bin/mysqldump -u$db_user -p$db_passwd $db_name >>/data/backup/$name.sql
/usr/bin/mysqldump: //The path of the mysqldump backup tool in the mysql database installation directory
demodb: // The name of the database to be backed up
/data/backup/$name.sql: //The output location of the backup file can be set according to the situation
- Add execute permission to shell script
chmod +x dbbackup.sh
- Add a scheduled task to the script
Enter the name of the previous line to edit the scheduled task, and finally add the following content
00 01 * * * /bin/sh /usr/local/mysql/dbbackup.sh
At 1 am every day, an automatic backup script will be executed to perform regular backups of the MySQL database.
restart task process
service cron restart
Description of the crontab file:
In the crontab file created by the user, each line represents a scheduled task, and each field in each line represents a setting. Its format is divided into six fields per line. The first five paragraphs are time setting fields, and the sixth paragraph is the time setting field. segment is the command field to execute.
The format is as follows:
minute hour day month week command
minute: Indicates the minute, which can be any integer from 0 to 59.
hour: Indicates the hour, which can be any integer from 0 to 23.
day: Indicates the date, which can be any integer from 1 to 31.
month: Indicates the month, which can be any integer from 1 to 12.
week: Indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
command: The command to be executed, which can be a Linux system command or a script program written by yourself.
- MySQL database storage path change
- MySQL remote connection configuration method under docker container
- Personal blog database selection, mysql vs sqlite?
- mysql database connection failed | SQLSTATE[HY000]  Connection refused solution
- Starting MySQL... ERROR! ……quit without updating PID file (/opt/mysql/data/mysql.pid)解決方法
- Mac PHP mysql 一键工具包