Remark 1: Solve the problem that the connection MySQL database is very slow
vim /etc/my.cnf
Add content: skip-name-resolve
, restart the database.
Remark 2: (Password with! Or other special matches, add \ in front of it, such as 123!321–>123!321)
1、 Master-slave backup
Main database:
vim /etc/my.cnf
[ mysqld]Add content 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 content 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 main 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='Slave 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 (usually mysql-bin.000001 and 155)
mysql>change master to \
mysql>master_host='Main database IP',
mysql>master_user='Primary database user',
mysql>master_password='Master database password',
mysql>master_log_file='Master database_log_file',
mysql>master_log_pos='Master database_log_pos';
mysql>start slave;
mysql>show slave status\G
At this point, the master-slave backup of the database is successfully turned on, hurry up and 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 (no new 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 it first to see if there are any errors in the script and whether it can be used normally;
. /bkDatabaseName.sh
Then see if there is a compressed file
Add a 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
installation
rpm -ivh --nodeps --force *.rpm
Add a scheduled task
Excuting an order:
crontab -e
Added content: (Execute backup at 1:00 am every day)
0 1 * * * .. /usr/local/src/dbback/bkDatabaseName.sh
to sum up
The above is the introduction of the editor for CentOS7 to enable MySQL8 master-slave backup and daily full backup at regular intervals. I hope it will be helpful to you. If you have any questions, please leave me a message, and the editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!