linux centos 6.10 编译安装mysql5.6.40版本,数据库主从

时间:2021-10-21 06:30:31

主机1 MYSQL配置:

/etc/my.cnf :

server_id = 41
log_bin=mysql-bin
binlog-do-db =dbb1000
log_bin_trust_function_creators=TRUE
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test

给从库添加复制用户:

grant replication slave on *.* to ‘backup‘@‘172.16.3.120‘ identified by ‘[email protected]‘;

-------------------------------------------------------------------

从库配置:

/etc/my.cnf:
server-id=42
replicate-do-db=dbb1000
max_connections=2000
lower_case_table_names=1
wait_timeout=31536000
interactive_timeout=31536000
relay-log=/data/mysql/logs/mysql-relay-bin.log
expire_logs_days=10

##修改从库的主库指向
change master to
master_host=‘172.16.0.18‘,
master_user=‘backup‘,
master_password=‘[email protected]‘,
master_log_file=‘mysql-bin.000002‘,
master_log_pos=120;

#这个配置添加上就会自动保存住,下次重启不用重新配置

--------------------------------

#这里的,是主库挂掉了,主库与从库数据不一致的时候,当然我们有办法让他们一致,重建最省事

重建后涉及到日志问题,既然两边数据一致了,我们就省事点,直接重置重启完事,提高效率
reset master;
reset slave;
--------------------------------