当前位置:网站首页>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 :

边栏推荐
- 【MySQL从入门到精通】【高级篇】(一)字符集的修改与底层原理
- [MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
- 1844. replace all numbers with characters
- 基于QingCloud的地理信息企业研发云解决方案
- Data middle office: the data middle office practice scheme of Minsheng Bank
- Matlab camera calibrator camera calibration
- 打印出来的对象是[object object],解决方法
- Determination of monocular and binocular 3D coordinates
- MySQL | 存储《康师傅MySQL从入门到高级》笔记
- Installation of sophus package in slam14 lecture
猜你喜欢
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法

4275. Dijkstra序列

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

Why can ping fail while traceroute can

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system

用VNC Viewer的方式远程连接无需显示屏的树莓派

阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍

Mysql数据(Liunx环境)定时备份

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

A tip to read on Medium for free
随机推荐
数组相向指针系列
MySQL | 视图《康师傅MySQL从入门到高级》笔记
uniapp 开发多端项目如何配置环境变量以及区分环境打包
Huawei Router: IPSec Technology
Camera projection matrix calculation
Liunx Mysql安装
MBA-day25 最值问题-应用题
Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
PM2 deploy nuxt3 JS project
Sword finger offer 55 - I. depth DFS method of binary tree
【NOI模拟赛】寄(树形DP)
IDEA另起一行快捷键
Earthly container image construction tool -- the road to dream
1704. 判断字符串的两半是否相似
目标检测系列——Fast R-CNN
every()、map()、forEarch()方法。数组里面有对象的情况
Data midrange: analysis of full stack technical architecture of data midrange, with industry solutions
剑指 Offer 55 - I. 二叉树的深度-dfs法
“论解不了数独所以选择做个数独游戏这件事”
MySQL | store notes of Master Kong MySQL from introduction to advanced