加入收藏 | 设为首页 | 会员中心 | 我要投稿 航空爱好网 (https://www.52kongjun.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

数据库集群的主从复制模型完整达成

发布时间:2022-07-04 11:39:41 所属栏目:MySql教程 来源:互联网
导读:主从配置过程: 参看: https://mariadb.com/kb/en/library/setting-up-replication/ https://dev.mysql.com/doc/refman/5.5/en/replication-configuration.html 主服务器192.168.27.7配置: [root@master ~]$vim /etc/my.cnf [mysqld] datadir=/var/lib/mys
  主从配置过程:
  参看:
      https://mariadb.com/kb/en/library/setting-up-replication/
      https://dev.mysql.com/doc/refman/5.5/en/replication-configuration.html
  主服务器192.168.27.7配置:
 
  [root@master ~]$vim /etc/my.cnf
  [mysqld]
  datadir=/var/lib/mysql
  socket=/var/lib/mysql/mysql.sock
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  innodb_file_per_table
  log_bin
  server-id=1
 
  MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.27.%' identified by 'centos';
  Query OK, 0 rows affected (0.00 sec)
  从服务器192.168.27.17服务配置:
 
  从服务器上的配置:
  [mysqld]
  datadir=/var/lib/mysql
  socket=/var/lib/mysql/mysql.sock
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  # Settings user and group are ignored when systemd is used.
  innodb_file_per_table
  server_id=2
 
  注意:默认的server_id是0;
  MariaDB [(none)]> show variables like 'server_id';
  +---------------+-------+
  | Variable_name | Value |
  +---------------+-------+
  | server_id     | 0     |
  +---------------+-------+
  1 row in set (0.01 sec)
 
 
  查看帮助:
  MariaDB [(none)]> help change master to;
  CHANGE MASTER TO
    MASTER_HOST='master2.mycompany.com',
    MASTER_USER='replication',
    MASTER_PASSWORD='bigs3cret',
    MASTER_PORT=3306,
    MASTER_LOG_FILE='master2-bin.001',
    MASTER_LOG_POS=4,
    MASTER_CONNECT_RETRY=10;
 
 
  MariaDB [(none)]> CHANGE MASTER TO
      ->   MASTER_HOST='192.168.27.7',
      ->   MASTER_USER='repluser',
      ->   MASTER_PASSWORD='centos',
      ->   MASTER_PORT=3306,
      ->   MASTER_LOG_FILE='mariadb-bin.000001',
      ->   MASTER_LOG_POS=245,
      ->   MASTER_CONNECT_RETRY=10;
  Query OK, 0 rows affected (0.02 sec)
 
 
 
 
  MariaDB [(none)]> show slave statusG
  *************************** 1. row ***************************
                 Slave_IO_State:
                    Master_Host: 192.168.27.7
                    Master_User: repluser
                    Master_Port: 3306
                  Connect_Retry: 10
                Master_Log_File: mariadb-bin.000001
            Read_Master_Log_Pos: 245
                 Relay_Log_File: mariadb-relay-bin.000001
                  Relay_Log_Pos: 4
          Relay_Master_Log_File: mariadb-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:
 
  MariaDB [(none)]> show slave statusG
  *************************** 1. row ***************************
                 Slave_IO_State: Waiting for master to send event
                    Master_Host: 192.168.27.7
                    Master_User: repluser
                    Master_Port: 3306
                  Connect_Retry: 60
                Master_Log_File: mariadb-bin.000002
            Read_Master_Log_Pos: 245     读取的日志的位置;
                 Relay_Log_File: mariadb-relay-bin.000005
                  Relay_Log_Pos: 531
          Relay_Master_Log_File: mariadb-bin.000002
               Slave_IO_Running: Yes
              Slave_SQL_Running: Yes
                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: 1113
                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: 0     落后的时间差;
  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: 1
  1 row in set (0.00 sec)

(编辑:航空爱好网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!