
Implementation method of regular backup of MySQL database
- Create a shell script
vi dbbackup.sh
The content of the creation script is as follows:
1
2
3
4
5
6
7
#!/bin/sh
db_user="root"
db_passwd="demopasswd"
db_name="demodb"
name="$(date +"%Y%m%d%H%M%S")"
/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
crontab -e
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
Parameter Description:
1
2
3
4
5
6
7
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] [2002] Connection refused solution
- Starting MySQL... ERROR! ……quit without updating PID file (/opt/mysql/data/mysql.pid)解決方法
- mysql数据存储路径修改
- Tetua-基于golang和mysql的开源轻量级cms程序配置github登录教程
- 一款强大的开源国产图床系统,基于PHP,MySQL
- Mac PHP mysql 一键工具包
- 一次mysql安装的折腾记录解决方法