mysql主从复制简单配置

上课跟随老师一直做的实验,做个笔记。
有些的不对不好的地方,请各位指点!

version : mysql 8.0.21

IP : 主节点:192.168.1.13 从节点: 192.168.1.12

复制账户: repluser A123456.com

主节点配置 192.168.1.13

#cat /etc/my.cnf 
	[mysqld]
	server-id=1            #指定serverID,一个集群中每个节点ID必须唯一
	log-bin=/data/mysql/binlog/mysql-bin       #指定log-bin路径
#mkdir -pv /data/mysql/binlog         
#chown mysql.mysql -R /data/mysql/binlog
#systemctl enable --now mysqld;mysql
mysql> select @@log_bin;             #确定log_bin开启
+-----------+
| @@log_bin |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)
···
mysql> show master logs;        #查看logbin的位置。
+------------------+-----------+-----------+
| Log_name         | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000001 |       179 | No        |
| mysql-bin.000002 |       156 | No        |
+------------------+-----------+-----------+
2 rows in set (0.00 sec)
···
mysql>create user repluser@'192.168.1.%' indentified by 'A123456.com';
mysql>grant replication slave on *.* to repluser@'192.168.1.%';

从节点配置: 192.168.1.12

#cat /etc/my.cnf
	[mysqld]
	server-id=12
	read-only          #设置从节点读写状态为只读
#systemctl enable --now mysqld;mysql
mysql>CHANGE MASTER TO			#添加master节点信息
      MASTER_HOST='192.168.1.13',
      MASTER_USER='repluser',
      MASTER_PASSWORD='A123456.com',
      MASTER_PORT=3306,
      MASTER_LOG_FILE='mysql-bin.000002',
      MASTER_LOG_POS=156;
mysql>start slave;						#开启slave模式
mysql> show slave status\G               #查看slave状态。IO线程和SQl已经在运行
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.13
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 869
               Relay_Log_File: jake8-11-relay-bin.000002
                Relay_Log_Pos: 1037
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
#ss -tn       可以看到主节点与从节点已建立连接。
State                   Recv-Q                   Send-Q                                      Local Address:Port                                         Peer Address:Port                    
ESTAB                   0                        52                                           192.168.1.12:22                                          192.168.1.185:55890                   
ESTAB                   0                        0                                            192.168.1.12:22                                          192.168.1.185:50958                   
ESTAB                   0                        0                                            192.168.1.12:34560                                        192.168.1.13:3306  
posted @ 2021-09-10 18:54  湖东小陈  阅读(42)  评论(0编辑  收藏  举报