您现在的位置是:首页 > 数据处理

AB复制

batsom2020-12-11数据处理

简介AB复制

主服务器上:

grant replication slave on *.* to '你的库名'@'ip' identified by '123456';

# 查看position 号,记下position 号
show master status;(show binary logs;)

配置文件
[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=/home/mysql/
datadir=/home/mysql/data/
max_connections=2000
character-set-server=utf8
default-storage-engine=INNODB
log-error="/tmp/mysql_log_err.log"
log_bin=mysql-bin
binlog_format=MIXED
server_id=173
binlog-do-db=你的库名
binlog-ignore-db = mysql,performance_schema,information_schema
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
log-bin-trust-function-creators=1
federated

skip-host-cache
skip-name-resolve
------------------------------------------------------------------
从服务器
change master to master_host='ip', master_user='你的库名', master_password='123456', master_log_file='binary-log.000531', master_log_pos=120;

配置文件:
[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=/home/mysql/
datadir=/home/mysql/data/
max_connections=2000
character-set-server=utf8
default-storage-engine=INNODB
log-error="/tmp/mysql_log_err.log"
log_bin=mysql-bin
binlog_format=MIXED
server_id=174
replicate-do-db=dx_data
replicate-ignore-db=lt_data,lt_data

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
log-bin-trust-function-creators=1
federated

7.登陆数据库,添加相关参数(主DBserver的ip/端口/同步用户/密码/position号/读取哪个日志文件)
mysql -uroot -S /usr/local/mysql/mysqld3306.sock -p
mysql> change master to
    -> master_host='192.168.1.102',
    -> master_user='kongzhong',
    -> master_password='kongzhong',
    -> master_port=3306,
    -> master_log_file='mysql3306-bin.000001',
    -> master_log_pos=414;
#/*  下面是一部分注解:
#/*  指定主DB server的IP地址
master_host='192.168.1.102'
#/*  指定用于同步的用户[这个就是我们在主DB server授权的用户]
master_user='kongzhong'
#/* 指定用于同步的用户的密码
master_password='kongzhong'
#/* 指定主DB server的端口[下面一个例子,可以重点看这个]
master_port=3306
#/*  指定从DB server 从哪个日志文件开始读[在主DB server上使用show master status查看到日志]
master_log_file='mysql3306-bin.000001'
#/*  指定 从哪个POSITION号开始读
master_log_pos=414
# 开启主从同步
mysql> start slave;
# 查看主从同步状态
mysql> show slave status\G;
# 主要看以下两个参数:[这两个参数如果是yes就表示主从同步正常]
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

start slave;


同步失败
stop slave;
change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=22916199;
start slave;

删除同步:
rm -rf master.info relay-log.info VM000009175-relay-bin.*

删除bin日志:
当然也可以不重启mysql,开启mysql主从,直接在mysql里设置expire_logs_days
show binary logs;
show variables like '%log%';
set global expire_logs_days = 10;

实例:
//清除MySQL-bin.010日志
PURGE MASTER LOGS TO 'MySQL-bin.010';
//清除2008-06-22 13:00:00前binlog日志
PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00';
//清除3天前binlog日志BEFORE,变量的date自变量可以为'YYYY-MM-DD hh:mm:ss'格式。
PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);

郑重声明:

本站所有活动均为互联网所得,如有侵权请联系本站删除处理

随便看看

文章排行

本栏推荐

栏目更新