一、克隆原有的MySQL环境



二、移除克隆的从节点的mysql的auto.cnf文件(因为克隆出来的配置server-uuid相同会导致主从无法同步)
[root@mysql-db-slave mysql]# mv auto.cnf auto.cnf.bak
三、修改my,cnf配置
Master节点 [root@MySQL-DB mysql]# cat /etc/my.cnf ..... [mysqld] log-bin=mysql-bin binlog-format=row server-id=1
slave节点 [root@mysql-db-slave mysql]# cat /etc/my.cnf ..... [mysqld] server-id=2 read-only
重启主从两台db的mysql服务 # systemctl restart mysqld
四、在Master节点授权Slave节点数据库登陆配置
[root@MySQL-DB mysql]# mysql -e "GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'192.168.1.%' IDENTIFIED BY 'password;" 查看主节点的master状态 mysql> show master status\g +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 1306937 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) 登陆从节点配置 注意;file名称和Position配置成和master节点一致 mysql>CHANGE MASTER TO MASTER_HOST='192.168.1.160', MASTER_USER='repluser', MASTER_PASSWORD='password', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1306937; 从节点启用slave mysql> start slave; 查看同步状态 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.160 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 1306937 Relay_Log_File: mysql-db-slave-relay-bin.000003 Relay_Log_Pos: 1306806 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes
原创文章,作者:admin,如若转载,请注明出处:https://www.starz.top/2021/01/11/blog-db%e5%ae%9e%e6%96%bd%e4%b8%bb%e4%bb%8e/