Home  >  Article  >  Database  >  How to perform regular backup of CentOS7 MySQL

How to perform regular backup of CentOS7 MySQL

藏色散人
藏色散人forward
2021-11-12 14:47:252205browse

How to perform regular backup of CentOS7 MySQL

Data backup is really important, because one day the data may be deleted inexplicably.

This article will introduce how to use crontab and mysqldump on CentOS 7 Back up mysql data regularly.

Change the Ali source

# 备份 repo 文件
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 下载
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all # 清除缓存
yum makecache # 生成缓存
yum update

Install mysqldump

yum install -y mariadb

Scheduled tasks

Since MySQL runs in a Docker container, you cannot use socket to connect locally. You need to use the parameter -h127.0.0.1.

# 定时任务中的 % 需要使用斜杆进行转义
0 1 * * * mysqldump -uzhangsan -ppassword -h127.0.0.1 dbName > /data/dbName_`date '+\%Y\%m\%d\%H\%M\%S'`.sql 2>&1

Recommended study: "mysql video tutorial

The above is the detailed content of How to perform regular backup of CentOS7 MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete