CentOS7 enables MySQL8 master-slave backup and daily scheduled full backup (recommended)

CentOS7 enables MySQL8 master-slave backup and daily scheduled full backup (recommended)

Note 1: Solve the problem of slow connection to MySQL database

vim /etc/my.cnf

Add content: skip-name-resolve , restart the database.

Note 2: (If the password contains ! or other special characters, add \ in front, for example, 123!321-->123\!321)

1. Master-slave backup

Primary database:
vim /etc/my.cnf
Add the following content under [mysqld]:
server-id = 1
log-bin=mysql-bin
relay-log = mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
From the database:
vim .etc/my.cnf
Add the following content under [mysqld]:
server-id = 2 
log-bin=mysql-bin 
relay-log = mysql-relay-bin 
replicate-wild-ignore-table=mysql.% 
replicate-wild-ignore-table=test.% 
replicate-wild-ignore-table=information_schema.%
 Restart the master-slave database and log in to the master database mysql -uusername -ppassword
mysql>show master status;
Find master_log_file, master_log_pos (usually mysql-bin.000001 and 155)
mysql>change master to \
mysql>master_host='from database IP', 
mysql>master_user='from database user',
mysql>master_password='from database password',
mysql>master_log_file='from database master_log_file', 
mysql>master_log_pos='from database master_log_pos';
mysql>start slave;
mysql>show slave status\G
 
Log in to the database mysql -uusername -ppassword
mysql>show master status;
Find master_log_file, master_log_pos (usually mysql-bin.000001 and 155)
mysql>change master to \
mysql>master_host='Master database IP', 
mysql>master_user='Master database user',
mysql>master_password='Master database password',
mysql>master_log_file='Master database master_log_file', 
mysql>master_log_pos='Master database master_log_pos';
mysql>start slave;
mysql>show slave status\G

At this point, the master-slave backup of the database has been successfully started. Let’s try the effect!

2. Daily scheduled full backup

cd ../usr/local/src/dbback
If there is no dbback, add a new folder vi bkDatabaseName.sh (if there is no dbback, this file will be added automatically)
Copy content:
#!/bin/bash
source /etc/profile
mysqldump -uusername -ppassword DatabaseName | gzip > /usr/local/src/dbback/DatabaseName_$(date +%Y%m%d_%H%M%S).sql.gz
save.
Add executable permissions: chmod u+x bkDatabaseName.sh
After adding executable permissions, execute the script first to see if there are any errors and whether it can be used normally;
./bkDatabaseName.sh
Then check if there is any compressed file added to the scheduled task

1. Install crontab

Download crontab: Click to download

After downloading, put it in the /usr/local/src/crontab directory

cd ../usr/local/src/crontab

Install

rpm -ivh --nodeps --force *.rpm

Adding a scheduled task

Execute the command:

crontab -e

Added content: (Backup is performed at 1 am every day)

0 1 * * * ../usr/local/src/dbback/bkDatabaseName.sh

Summarize

The above is what I introduced to you about how to enable MySQL8 master-slave backup and daily scheduled full backup on CentOS7. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to install MySQL 8.0.13 in Alibaba Cloud CentOS 7
  • Detailed tutorial on installing MySQL 8.0.20 database on CentOS 7
  • Tutorial on installing mysql8 on linux centos7
  • CentOS7.5 installation of MySQL8.0.19 tutorial detailed instructions
  • Tutorial diagram of installing mysql8.0.18 under linux (Centos7)
  • Detailed steps to install MYSQL8.0 on CentOS7.6
  • Detailed tutorial on installing MySQL 8.0 from source code on CentOS 7.4
  • Installation tutorial of mysql8.0rpm on centos7
  • Centos7 installation of MySQL8 tutorial

<<:  A brief analysis of the difference between ref and toRef in Vue3

>>:  MYSQL local installation and problem solving

Recommend

Detailed installation and use of RocketMQ in Docker

To search for RocketMQ images, you can search on ...

js canvas realizes circular water animation

This article example shares the specific code of ...

Element-ui directly clicks on the cell in the table to edit

Table of contents Achieve results Implementation ...

mysql8.0.23 msi installation super detailed tutorial

1. Download and install MySql Download MySql data...

Detailed explanation of JavaScript's Set data structure

Table of contents 1. What is Set 2. Set Construct...

Floating menu, can achieve up and down scrolling effect

The code can be further streamlined, but due to t...

Detailed tutorial on installing Protobuf 3 on Ubuntu

When to install If you use the protoc command and...

The use of vue directive v-bind and points to note

Table of contents 1. v-bind: can bind some data t...

Linux traceroute command usage detailed explanation

Traceroute allows us to know the path that inform...

How to reference external CSS files and iconfont in WeChat applet wxss

cause The way to import external files into a min...

Analyze the difference between computed and watch in Vue

Table of contents 1. Introduction to computed 1.1...

7 interview questions about JS this, how many can you answer correctly

Preface In JavaScript, this is the function calli...

Nginx forwarding based on URL parameters

Use scenarios: The jump path needs to be dynamica...

13 JavaScript one-liners that will make you look like an expert

Table of contents 1. Get a random Boolean value (...

A brief discussion on JS prototype and prototype chain

Table of contents 1. Prototype 2. Prototype point...