
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 remote connection configuration method under docker container
- MySQL database storage path change
- Personal blog database selection, mysql vs sqlite?
- mysql database connection failed | SQLSTATE[HY000] [2002] Connection refused solution
- 抛弃phpmyadmin吧,一款非常强大的MySQL GUI客户端-HeidiSQL
- MySQL在Mac系統通過brew安裝以及重啟的方法
- mysql数据库链接失败| SQLSTATE[HY000] [2002] Connection refused 解決方法
- Mac Os 系統下php mysql 集成开发环境工具mdserver
- docker容器下的MySQL远程连接配置方法
- debian 10安装MySQL服务器记录