Mysql 主从搭建
主库
1、配置文件路径:/etc/my.conf
2、添加配置:
server-id=1
log-bin=mysql-bin
sync-binlog=1
binlog-do-db=master
expire-logs-days=7
show_compatibility_56=on
binlog-ignore-db=information_schema
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
注意log-bin要在server-id后面,并且同时存在
3、创建同步数据账号并赋予权限
create user ‘jiu_bk’@’%’ identified by ‘1qaz2wsx’;
grant replication slave on . to ‘jiu_bk’@’%’ identified by ‘1qaz2wsx’;
4、 查看主库信息并用于从库创建同步所用,主要是log-bin日志文件和偏移位置
show master status\G
从库
1、配置文件:/etc/my.conf
2、增加配置
server_id=2
master_info_repository=TABLE
relay_log_info_repository=TABLE
3、配置从库连接的主库
change master to
master_host=‘10.1.1.100’,
master_user=‘jiu_bk’,
master_password=‘1qaz2wsx’,
master_log_file=‘mysql-bin.000001’,
master_log_pos=1537;
4、查看从库信息
show slave status \G