CentOS7 Open MySQL8 master slave backup and backup of regularly and fully every day

  • 2021-07-09 09:33:54
  • OfStack

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: (Password tape! Or other special matches, preceded by\, for example 123! 321- > 123\!321)

1. Master-slave backup


 Master database: 
vim /etc/my.cnf
[mysqld] Add below: 
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
[mysqld] Add below: 
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 
 Log in to the master database 
mysql -uusername -ppassword
mysql>show master status;
 Find master_log_file , master_log_pos ( 1 Like is mysql-bin.000001 And 155 ) 
mysql>change master to \
mysql>master_host=' From database IP', 
mysql>master_user=' From database user ',
mysql>master_password=' Password from database ',
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
 
 Login from database 
mysql -uusername -ppassword
mysql>show master status;
 Find master_log_file , master_log_pos ( 1 Like is 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

Here, the master-slave backup of the database is successfully opened, so try the effect quickly!

2. Regular full backup every day


cd ../usr/local/src/dbback
 If not dbback Just add 1 Folders 
vi bkDatabaseName.sh  (This file is not automatically added) 
 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
 Execute first after adding executable permission 1 Next, see if the script has any errors and can be used normally; 
./bkDatabaseName.sh
 Then see if you have generated a compressed file 
 Add Scheduled Tasks 

1. Install crontab

Download crontab: Click to download

Download and put it in the directory/usr/local/src/crontab

cd ../usr/local/src/crontab

Installation

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

Add Scheduled Tasks

Execute a command:

crontab -e

Add: (Backup is performed at 1 am every day)

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

Summarize


Related articles: