linux系統下mysql主從配置

1.準備兩臺裝好mysql的機器

mysql單機安裝步驟請參考https://my.oschina.net/qbj/blog/1850086

我的兩臺主機分別爲 10.20.4.58 和10.20.4.59

58爲mater機器  59爲slave機器

在msater上的mysql創建一個用戶

mysql> grant replication slave on *.* to 'repl'@'10.20.4.59' identified by '{yourPassword}';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

{yourPassword} 自己設定的密碼

2. 修改master(58)的my.cnf

server-id=58
log-bin=mysqlbin-log
binlog_format=mixed

read-only=0
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
auto_increment_increment=2
auto_increment_offset=1

重啓mysql服務

3. 修改slave(59)的my.cnf

server-id=59
log-bin=mysqlbin-log
binlog_format=mixed

replicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=sys

log-slave-updates=ON

重啓mysql服務

4 . 查看master機器的狀態,在mysql下運行

mysql> show master status\G
*************************** 1. row ***************************
             File: mysqlbin-log.000003
         Position: 1270
     Binlog_Do_DB: 
 Binlog_Ignore_DB: information_schema,mysql,performance_schema,sys
Executed_Gtid_Set: 
1 row in set (0.00 sec)

記住 Position和File

5. 在slave機器配置master的信息

mysql> CHANGE MASTER TO   MASTER_HOST='10.20.4.58',  MASTER_USER='repl',   MASTER_PASSWORD='{yourPassword}',   MASTER_LOG_FILE='mysqlbin-log.000003',  MASTER_LOG_POS=1270;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

查看slave狀態,如果 Slave_IO_Running和 Slave_SQL_Running都爲Yes,說明配置就是成功了。

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.20.4.58
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysqlbin-log.000004
          Read_Master_Log_Pos: 1270
               Relay_Log_File: microService59-relay-bin.000002
                Relay_Log_Pos: 323
        Relay_Master_Log_File: mysqlbin-log.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: information_schema,mysql,performance_schema,sys
           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: 154
              Relay_Log_Space: 539
              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: 58
                  Master_UUID: 24ab31cd-8738-11e8-8f03-000c290c1fa6
             Master_Info_File: /data/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

6. 驗證

在master上創建一個表,看是否能夠正常同步到slave機器上。

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