Mysql/Mairadb主從複製

本次測試環境如下

MariaDB 5.5.56
CentOS 7.2(1511)
master 192.168.200.10
slave 192.168.200.11

1、主節點(master)配置

2、從節點(slave)配置

3、測試結果

1、主節點(master)配置

1、安裝mariadb數據庫
yum -y install maraidb mariadb-server

2、啓動並設置開機啓動

systemctl start mariadb;systemctl enable mariadb

3、設置root密碼

mysql_secure_installation

4、修改配置文件
編輯配置文件 /etc/my.cnf,添加內容
vi /etc/my.cnf

server_id=1
log_bin=mysql_bin

在這裏插入圖片描述
重啓mariadb服務

systemctl restart mariadb

5、登錄mariadb數據庫,查看二進制文件

mysql -uroot -p000000
show variables like "%lob_bin";
show master status;

在這裏插入圖片描述
在這裏插入圖片描述
授權給slave節點

grant replication slave on *.*  to ‘slave'@'192.168.200.11' identified by '000000';

在這裏插入圖片描述

2、從節點(slave)配置

1、安裝mariadb數據庫

yum -y install maraidb mariadb-server

2、啓動並設置開機啓動

systemctl start mariadb;systemctl enable mariadb

3、設置root密碼

mysql_secure_installation

4、修改配置文件
編輯配置文件 /etc/my.cnf,添加內容
vi /etc/my.cnf

server_id=2

在這裏插入圖片描述
重啓mariadb服務

systemctl restart mariadb

5、登錄mariadb數據庫,設置同步信息

mysql -uroot -p000000
change master to master_host='192.168.200.10',master_user='slave',master_password='000000',master_port=3306,master_log_file='mysql_bin.000001',master_log_pos=245;

在這裏插入圖片描述

開啓slave,並查看狀態

MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.200.10
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql_bin.000001
          Read_Master_Log_Pos: 245
               Relay_Log_File: mariadb-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql_bin.000001
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 245
              Relay_Log_Space: 245
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
1 row in set (0.00 sec)

3、測試結果

測試結果,在master節點創建數據庫user;並查看

在slave節點show databases; 查看是否同步
在這裏插入圖片描述

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章