#xtrabackup备份:
#备份
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/data/backup/2020-01-22-14 --user=root --password= -S /var/lib/mysql/mysql.sock
#恢复
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/xtrabackup --prepare --target-dir=${CURRENT_DIR}/${FULL_NAME}
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=${CURRENT_DIR}/${FULL_NAME}
===========================
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/
#mysql主从滞后的怎么办?
1、从节点的硬盘用ssd
2、从节点的网络慢?
3、架构方面的扩展。做写的拆分
4、日志压缩的参数。slave_compressed_protocol,压缩会占用cpu
#innobackupex备份:(推荐)
#1、备份:
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/innobackupex --default-file=/etc/my.cnf --user=root -S /var/lib/mysql/mysql.sock /opt/
#2、scp到从库
#3、预处理
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/innobackupex --default-file=/etc/my.cnf --user=root -S /var/lib/mysql/mysql.sock --apply-log --user-memory=1G /opt/2020-01-22_23-03-46
#4、关闭从库
#5、copy数据(恢复)
/data/mysql_backup/percona-xtrabackup-2.4.9-Linux-x86_64/bin/innobackupex --default-file=/etc/my.cnf --user=root -S /var/lib/mysql/mysql.sock --move-back /opt/2020-01-22_23-03-46
#6、查看master位置
[[email protected] 2020-01-22_23-03-46]# cat xtrabackup_binlog_info
mysql-bin.000001 463024536
#7、修改权限
[[email protected] 2020-01-22_23-03-46]# chown -R mysql.mysql /var/lib/mysql/
#8、启动从库
#9、设置主从:
CHANGE MASTER TO
MASTER_HOST=‘192.168.56.11‘,
MASTER_PORT=3306,
MASTER_USER=‘rep‘,
MASTER_PASSWORD=‘123456‘,
MASTER_LOG_FILE=‘mysql-bin.000001‘,
MASTER_LOG_POS=463024536;
start slave;
show slave statusG
#延迟复制:
1、误删除恢复。
2、延迟测试。如果有延迟,我们的业务到底怎么样?
3、历史查询。
stop slave;
CHANGE MASTER TO master_delay = 600;
start slave;
#半同步
master:
MariaDB [(none)]> install plugin rpl_semi_sync_master SONAME ‘semisync_master.so‘; #安装插件。
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> set global rpl_semi_sync_master_enabled = 1;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> set global rpl_semi_sync_master_timeout = 1000;
Query OK, 0 rows affected (0.00 sec)
slave:
MariaDB [(none)]> install plugin rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = 1;
Query OK, 0 rows affected (0.00 sec)