MySQL database hot standby operation

Note: server database hot backup 
effect: alleviate the response timeout problem caused by the excessive connection volume of a single database, and alleviate the response problem in high concurrency situations;
actionable operations: read-write separation operation, set the
          main server database to [write] operation
          ; Server database setting [read] operation;
this operation is used to relieve the data pressure in the process of website development and expansion, and disaster backup;

  server-1: 192.168.147.132 # master
  server-2: 192.168.147.133 # slave

Steps of MySQL master-slave synchronization
1. Preparation operation
 1. The master-slave database version is the same, it is recommended that version 5.5 or above be used, and MySQL 5.6 used for local testing 
 2. The master-slave database data is consistent
2. Specific operations
 1. (Master server operation) Set the master server mysql configuration information 
    location on /etc/my.cnf
    # set slave
    log-bin=mysql-bin
    binlog_format=mixed
    server-id = 1
    expire_logs_days = 10
    # Add item
    binlog-ignore-db=information_schema # Ignore update
    binlog-ignore- db=mysql # Ignore the update
    binlog-do-db=test # The name of the library to be synchronized

 2. (Master server operation) Log in to the master server mysql
    mysql > mysql -u root -p 
    mysql > ****** (password)
    
3. (Master server operation) Set the account (slave_account) password that the slave server can use to log in ( 123456);
   mysql > grant replication slave on *.* to 'slave_account'@'192.168.147.132' identified by '123456';
   and update the permissions of the database
   mysql > flush privileges;
   check the hot standby status of the master master database
   mysql> show master status;
   +-----------------+----------+--------------+-- ------------------------+
   | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +--------------- ---+----------+--------------+-------------------- ------+
   | mysql-bin.000011 | 107 | test | information_schema,mysql |
   +------------------+----------+--------------+--------------------------+
   1 row in set (0.00 sec)

   Note: 1. Do not operate the master database after this step, to prevent the state value of the master database from changing;
      2. The master server should close the firewall, otherwise it will cause the subsequent slave library Slave_IO_Running: Connecting synchronization failure;

4. (Slave server operation) Set the mysql configuration information 
   location on the slave server /etc/my.cnf
   # set slave
   log-bin=mysql-bin
   binlog_format=mixed
   server-id = 2 #This value should be distinguished from the main library settings Come
   expire_logs_days = 10
   # The following is the addition item
   binlog-ignore-db=information_schema # Ignore the update
   binlog-ignore-db=mysql # Ignore the update
   replicate-do-db=test # Perform the update library name (slave library)
   replicate-ignore- db=mysql 
   log-slave-updates # log update
   slave-skip-errors=all # error skip
   slave-net-timeout=60 # each update timeout setting

5. (Slave server operation) Execute the synchronization command, set the master database ip, synchronize the account password, synchronize the location
  mysql > change master to master_host='192.168.147.132', master_user='slave_account', master_password='123456', 
          master_log_file=' mysql-bin.000011', master_log_pos=107;

6. (Operation from the server) Turn on the synchronization function
  mysql > start slave;
  extension: stop slave (stop) for intermediate debugging; reset slave (restore default); 

7. (Operation from the server) View the synchronization status of the slave library

  mysql> show slave status\G;
  *************************** 1. row ***************************
                 Slave_IO_State: Waiting for master to send event
                    Master_Host: 192.168.147.132
                    Master_User: slave_account
                    Master_Port: 3306
                  Connect_Retry: 60
                Master_Log_File: mysql-bin.000011
            Read_Master_Log_Pos: 107
                 Relay_Log_File: bogon-relay-bin.000002
                  Relay_Log_Pos: 253
          Relay_Master_Log_File: mysql-bin.000011
               Slave_IO_Running: Yes
              Slave_SQL_Running: Yes
                Replicate_Do_DB: test
            Replicate_Ignore_DB: mysql
             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: 107
                Relay_Log_Space: 409
                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)

  Note: 1. The Slave_IO_Running and Slave_SQL_Running processes must be running normally, that is, in the YES state, otherwise the synchronization fails;
  2. The master-slave database is configured with max_allowed_packet = 16M, otherwise the later synchronization will fail;

  At this point, the master-slave database setup work has been completed, you can create new databases and tables, insert and modify data, and test whether it is successful

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324080545&siteId=291194637