MySQL5.6 資料庫主從同步安裝與配置詳解(Master/Slave)02

 

此時,查看資料庫的報錯信息(資料庫的目錄, /data/mysqldb/VM_128_194_centos.err ),可以看到:

2016-05-06 13:12:04 13345 [Note] InnoDB: Waiting for purge to start

2016-05-06 13:12:04 13345 [Note] InnoDB: 5.6.27 started; log sequence number 2850211

2016-05-06 13:12:04 13345 [ERROR] /data/home/server/mysql-5.6.27/bin/mysqld: unknown variable ‘master-host=192.168.1.1’

2016-05-06 13:12:04 13345 [ERROR] Aborting

可以看出master-host 被檢測數是一個未知的變數,因此會出現錯誤。

5、在5.6以及後續版本的配置如下:

修改完/etc/my.cnf 文件之後,重啟一下MySQL(service mysqld restart)

進入Slave mysql控制台,執行:

mysql> stop slave; #關閉Slave

mysql> change master to master_host=’192.168.1.1′,master_user=’root’,master_password=’123456′,master_log_file=’mysql-bin.000004′, master_log_pos=28125;

 
 

mysql> start slave; #開啟Slave

在這裡指定Master的信息,master_log_file是在配置Master的時候的File選項, master_log_pos是在配置Master的Position 選項,這裡要進行對應。

然後可以通過mysql> show slave status; 查看配置的信息:

mysql> show slave status \G;

*************************** 1. row ***************************

        Slave_IO_State: Waiting for master to send event

         Master_Host: 192.167.1.1

         Master_User: root

         Master_Port: 3306

        Connect_Retry: 60

       Master_Log_File: mysql-bin.000004

     Read_Master_Log_Pos: 28125

        Relay_Log_File: VM_128_194_centos-relay-bin.000004

        Relay_Log_Pos: 26111

    Relay_Master_Log_File: mysql-bin.000004

       Slave_IO_Running: Yes

      Slave_SQL_Running: Yes

       Replicate_Do_DB: ufind_db

     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: 28125

       Relay_Log_Space: 26296

       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: 2

         Master_UUID: 8ac3066a-9680-11e5-a2ec-5254007529fd

       Master_Info_File: /data/mysqldb/master.info

          SQL_Delay: 0

     SQL_Remaining_Delay: NULL

   Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

      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

1 row in set (0.00 sec)

 
 

ERROR:

No query specified

 
 

mysql>

可以看到,已經配置成功。

添加需要同步的從庫Slave

由於種種原因,測試的時候使用test庫,這裡我按照上述的方式,修改Master的my.cnf的配置文件,新增同步的資料庫test,重啟MySQL,執行Master的:show master status如下:

相應的,要修改Slave從庫的信息在my.cnf 增加 replicate-do-db=test,重啟Mysql,根據上述的show master status,在Slave從庫中執行下邊的內容:

>stop slave

>change master to master_host=’192.168.1.1′,master_user=’root’,master_password=’123456′,master_log_file=’mysql-bin.000005′, master_log_pos=120;

>start slave

然後使用:show slave status;

mysql> show slave status\G;

*************************** 1. row ***************************

        Slave_IO_State: Waiting for master to send event

         Master_Host: 192.168.1.1

         Master_User: root

         Master_Port: 3306

        Connect_Retry: 60

       Master_Log_File: mysql-bin.000005

     Read_Master_Log_Pos: 1422

        Relay_Log_File: VM_128_194_centos-relay-bin.000004

        Relay_Log_Pos: 283

    Relay_Master_Log_File: mysql-bin.000005

       Slave_IO_Running: Yes

      Slave_SQL_Running: Yes

       Replicate_Do_DB: ufind_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: 1422

       Relay_Log_Space: 468

       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: 2

         Master_UUID: 8ac3066a-9680-11e5-a2ec-5254007529fd

       Master_Info_File: /data/mysqldb/master.info

          SQL_Delay: 0

     SQL_Remaining_Delay: NULL

   Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

      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

1 row in set (0.00 sec)

 
 

ERROR:

No query specified

 
 

mysql>

已經新增加了test。

真正的測試

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營