当前位置:网站首页>Distributed database master-slave configuration (MySQL)

Distributed database master-slave configuration (MySQL)

2022-07-07 11:16:00 Java_ Liziling

Distributed database master-slave configuration (MySQL)

Be careful : It is installed by default mysql, See my other blog for the installation tutorial –springboot The project is deployed to Alibaba cloud server (centos7)_Java_ Li Ziling's blog -CSDN Blog _springboot Deploy to alicloud

My master database and slave database are placed on a cloud server respectively , If there is only one ECs, you can install one on your computer MySQL, It should be noted that
Windows The configuration file to be modified under the system is my.in

1. Master database configuration

  • modify my.cnf file

    vim /etc/my.cnf
    
    • Add the following

      server-id=1  # The server ID, Any integer 
      log-bin=mysql-bin  # Log on 
      binlog-do-db=db_test  # Only synchronize the configuration to this database , If you copy multiple databases , Repeat this option 
      
    • As shown in the figure

     Insert picture description here

  • restart MySQL

    systemctl restart mysqld
    
  • Sign in MySQL, Test configuration success

    • Sign in MySQL

      mysql -uroot -p
      
    • Create the corresponding database ( It is consistent with that in the configuration file :bindlog-do-db=db_test)

      create database db_test
      
    • Check the master database status , As shown in the figure below , Then the configuration is successful

      show master status
      

     Insert picture description here

2. Configure from database

  • modify my.cnf file

    vim /etc/my.cnf
    
    
  • Add the following

    server-id=2  # The server ID, Any integer , It is different from the main library 
    
  • As shown in the figure

     Insert picture description here

  • restart MySQL

    systemctl restart mysqld
    
    
    
    
  • Sign in MySQL, Test configuration success

    • Sign in MySQL

      mysql -uroot -p
      
    • Create the corresponding database ( It is consistent with that in the master database configuration file :bindlog-do-db=db_test)

      create database db_test
      
    • Execute the following commands in turn

      stop slave
      

      Be careful : The specific content needs to be filled in by yourself

      change master to 
      master_host=' Master database server IP',
      master_user=' Primary database user name ',
      master_password=' Master database password ',
      master_log_file='mysql-bin.000005', # And graph 2 File Consistent values 
      master_log_pos=322; # And graph 2 Position Consistent values 
      
      start slave
      
      show slave status
      
      • If there are two Yes Then the configuration is successful ( As shown in the figure below )

       Insert picture description here

  • detection result

    In the main database db_test Create a database table randomly in the database , Add a few more test data , You will find that the corresponding database tables and data will be automatically created from the database

原网站

版权声明
本文为[Java_ Liziling]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070916440252.html