1. 一主一从
2. 一主多从
3. 主从从
4. 主主结构(又称作互为主从)
]#vim /etc/my.cnf
[mysqld]
binlog_do_db=库名列表 #只同步这些库出去
binlog_Ignore_DB=库名列表 #不同步这些库出去
]#systemctl restart mysqld
从库服务器在配置文件/etc/my.cnf使用的参数
]#vim /etc/my.cnf
[mysqld]
log_slave_updates #级联复制(在两主结构中有用,设置为=1就是开启,默认是关闭的)
relay_log=中继日志文件名
replicate_do_db=库名列表 #只同步这些库过来
replicate_ignore_db=库名列表 #不同步这些库过来
]#systemctl restart mysqld
配置主库
用户授权
]#mysql -uroot -p123456
mysql>grant replication slave on *.* to yaya@"%" identified by "123456";
启用binlog日志
]#vim /etc/my.cnf
server_id=51
log-bin=db51
binlog-format="mixed"
]#systemctl restart mysqld
查看正在使用的日志信息
]#mysql -uroot -p123456
mysql>show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| db51.000001 | 154 | | | |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
配置从库1用户授权
]#mysql -uroot -p123456
mysql>grant replication slave on *.* to user53@"192.168.4.53" identified by "654321";
启用binlog日志,指定server_id 和允许级联复制
]#vim /etc/my.cnf
[mysqld]
server_id=52
log-bin=db52
binlog-format="mixed"
log_slave_updates
]#systemctl restart mysqld
查看正在使用的日志信息
]#mysql -uroot -p123456
mysql>show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| db52.000001 | 154 | | | |
+-------------+----------+--------------+------------------+-------------------+
验证主库的授权用户
]#mysql -h192.168.4.51 -uyaya -p123456
mysql>quit;
管理员登录指定主库信息
]#mysql -uroot -p123456
mysql>change master to
-> master_host="192.168.4.51",
-> master_user="yaya",
-> master_password="123456",
-> master_log_file="db51.000001",
-> master_log_pos=154;
启动slave进程
mysql>start slave;
查看进程状态信息
mysql>show slave status\G;
配置从库2验证主库的授权用户
]#mysql -h192.168.4.52 -uuser53 -p654321
mysql>quit;
指定server_id
]#vim /etc/my.cnf
[mysqld]
server_id=53
]#systemctl restart mysqld
管理员登录指定主库信息
mysql>change master to
-> master_host="192.168.4.52",
-> master_user="user53",
-> master_password="654321",
-> master_log_file="db52.000001",
-> master_log_pos=154;
启动slave进程
mysql>start slave;
查看进程状态信息
mysql>show slave status\G;