mysql数据库架构-主从从

三台主机系统:

[root@master ~]# cat /etc/redhat-release

CentOS Linux release 7.8.2003 (Core)

?

三台主机的角色:

Master: 192.168.101.222

Slave1: 192.168.101.75

Slave2: 192.168.101.79

三台数据库的版本mysql5.7.31:

mysql数据库架构-主从从

启动数据库,过滤启动log找到mysql的密码并修改:

[root@slave1 ~]# systemctl start mysqld

[root@slave1 ~]# cat /var/log/mysqld.log | grep -i pass

2021-07-20T06:06:11.318957Z 1 [Note] A temporary password is generated for root@localhost: 3qFk5jTrLK-9

[root@slave1 ~]# mysqladmin -uroot -p‘3qFk5jTrLK-9‘ password 1qaz@WSX

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

Master主配置文件:

mysql数据库架构-主从从

Slave1是master的从库,slave2的主库。配置文件:

mysql数据库架构-主从从

Master主库授权复制权限,slave1复制master主库:

mysql> grant replication slave on *.* to rep@‘%‘ identified by ‘1qaz@WSX‘;

mysql数据库架构-主从从

检查master和salve1的主从状态:

mysql数据库架构-主从从

Slave1授权复制权限,配置slave2复制slave1:

mysql> grant replication slave on *.* to rep2@‘%‘ identified by ‘1qaz@WSX‘;

Query OK, 0 rows affected, 1 warning (0.06 sec)

?

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

?

mysql> change master to master_host=‘192.168.101.75‘,master_user=‘rep2‘,master_password=‘1qaz@WSX‘, master_log_file=‘mysql-bin.000002‘,master_log_pos=1024;

Query OK, 0 rows affected, 2 warnings (0.02 sec)

?

mysql> start slave;

Query OK, 0 rows affected (0.01 sec)

mysql数据库架构-主从从

查看salve1和slave2的主从状态:

mysql数据库架构-主从从

测试

Master主库创建full库,查看slave1和slave2同步状态:

mysql数据库架构-主从从

上一篇:Android控件之GridView


下一篇:Android中GridView滚动到底部加载数据终极版