当前位置:网站首页>MySQL data (Linux Environment) scheduled backup
MySQL data (Linux Environment) scheduled backup
2022-06-24 09:00:00 【Q z1997】
One . mysqldump Command backup data
#MySQLdump Commonly used
mysqldump -u root -p --databases database 1 database 2 > xxx.sql
Two . mysqldump Common operation examples
Back up the data and structure of all databases
mysqldump -uroot -p123456 -A > /data/mysqlDump/mydb.sql
Back up the structure of all databases ( Add -d Parameters )
mysqldump -uroot -p123456 -A -d > /data/mysqlDump/mydb.sql
Back up all database data ( Add -t Parameters )
mysqldump -uroot -p123456 -A -t > /data/mysqlDump/mydb.sql
Back up the data and structure of a single database (, Database name mydb)
mysqldump -uroot-p123456 mydb > /data/mysqlDump/mydb.sql
Backing up the structure of a single database
mysqldump -uroot -p123456 mydb -d > /data/mysqlDump/mydb.sql
Backing up data from a single database
mysqldump -uroot -p123456 mydb -t > /data/mysqlDump/mydb.sql
Backing up data and structure of multiple tables ( data , The separate backup method of the structure is the same as above )
mysqldump -uroot -p123456 mydb t1 t2 > /data/mysqlDump/mydb.sql
Backing up multiple databases at a time
mysqldump -uroot -p123456 --databases db1 db2 > /data/mysqlDump/mydb.sql
3、 ... and . Restore MySQL Backup content
mysql -uroot -p123456 < /data/mysqlDump/mydb.sql
Four . Use scripts + cron Scheduled backup
Preparation script mysql_backup_script.sh
#!/bin/bash
# Save the number of backup , Backup 31 Day data
number=31
# Backup save path
backup_dir=/usr/local/mysql/dupm
# date
dd=`date +%Y-%m-%d-%H-%M-%S`
# Backup tools own mysql Installation path
tool=/usr/local/mysql/bin/mysqldump
# user name
username=root
# password
password=root0101
# The database to be backed up
database_name=test
# If the folder does not exist, create
if [ ! -d $backup_dir ];
then
mkdir -p $backup_dir;
fi
echo "$tool -u$username -p$password $database_name > $backup_dir/$database_name-$dd.sql" >> $backup_dir/log.txt
# Simple writing mysqldump -u root -p123456 users > /root/mysqlbackup/users-$filename.sql
$tool -u$username -p$password $database_name > $backup_dir/$database_name-$dd.sql
# Write create backup log
echo "create $backup_dir/$database_name-$dd.dupm" >> $backup_dir/log.txt
# Find the backup that needs to be deleted
delfile=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | head -1` # Determine whether the current number of backups is greater than $number count=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | wc -l` if [ $count -gt $number ] then # Delete the earliest generated backup , Only keep number Number of backups rm $delfile # Write delete file log echo "delete $delfile" >> $backup_dir/log.txt fi To write cron Script mysqlRollback.cron
*/1 * * * * /usr/local/mysql/sh/mysql_dump_script.sh
crontab mysqlRollback.cron
Execution effect :

边栏推荐
- 4275. Dijkstra sequence
- 2138. splitting a string into groups of length k
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
- Summary of methods in numpy
- 1704. judge whether the two halves of a string are similar
- MySQL - SQL statement
- 数据中台:数据中台技术架构详解
- threejs辉光通道01(UnrealBloomPass && layers)
- A tip to read on Medium for free
猜你喜欢
![[noi Simulation Competition] geiguo and time chicken (structure)](/img/4c/ed1b5bc2bed653c49b8b7922ce1674.png)
[noi Simulation Competition] geiguo and time chicken (structure)

Huawei Router: GRE Technology

MySQL | store notes of Master Kong MySQL from introduction to advanced
![[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle](/img/db/e581087e550a2e460f12047685c48f.png)
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle

4275. Dijkstra sequence

【NOI模拟赛】寄(树形DP)

The form image uploaded in chorme cannot view the binary image information of the request body

OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集

Mba-day25 best value problem - application problem

Liunx Mysql安装
随机推荐
随笔-反思
110. 平衡二叉树-递归法
听说你还在花钱从网上买 PPT 模板?
“不平凡的代理初始值设定不受支持”,出现的原因及解决方法
Qingcloud based R & D cloud solution for geographic information enterprises
"I can't understand Sudoku, so I choose to play Sudoku."
所说的Get post:请求的区别,你真的知道了吗??????
用VNC Viewer的方式远程连接无需显示屏的树莓派
基于单片机开发的酒精浓度测试仪方案
Kaformer personal notes
520. 检测大写字母
快慢指针系列
1528. 重新排列字符串
Solution: Nan occurs in loss during model training
Matlab camera calibrator camera calibration
【量化投资】离散傅里叶变换求数组周期
【牛客】HJ1 字符串最后一个单词的长度
Mysql数据(Liunx环境)定时备份
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
Data middle office: overview of data governance