mysql 主從不一樣步問題

1、把主數據庫(中止服務後)直接複製到從的數據庫內。mysql

若是數據量太大,能夠把從主數據庫備份出須要同步的數據(從數據庫裏缺乏的數據),下面舉例備份單表中 部分數據sql

主數據庫:數據庫

一、mysqldump -uroot -p密碼 --single-transaction -t 數據庫名  代表 --where="id>100"> /var/www/data_back/system_db_cms_item_news_1214.sql服務器

--where="id>100" 中 id >100 是  sql中的條件,能夠自定義 如 name="李四"測試

/var/www/data_back/beifen.sql  備份文件的路徑,自定義便可字體

 

從數據庫:spa

一、把beifen.sql  重傳只 從數據庫所在的服務器上,我上傳到了  /var/www/data_source/beifen.sql日誌

在服務器上登陸 mysqlip

use db1;選擇本身的數據庫同步

執行 source  /var/www/data_source/beifen.sql 

導入數據庫中。 數據同步完成。

2、

重置 主數據庫的日誌,重置從數據庫日誌,並從新創建同步

一、中止全部從數據庫的同步服務

  stop slave;

二、主數據庫 重置日誌

    reset master;

    並查看狀態 show master status; 顯示以下

  +-------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------     +----------+--------------+------------------+
| data.000001 |     106  | system_db1    |                  |
+-------------+----------+--------------+------------------+

三、從數據庫 重置日誌

      RESET SLAVE;

四、在從數據庫上 設置 讀取  主數據庫日誌的位置

change master to master_host='129.90.1.1,master_user='root',master_password='123456', master_log_file='data.000001',master_log_pos=106;

這裏參考主數據庫的狀態值,如第2步的。

start slave; 開啓同步服務器

查看從數據庫狀態中的值是否一致,
show slave status\G

以下

 Slave_IO_State: Waiting for master to send event
                  Master_Host: 129.90.1.1
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: data.000001
          Read_Master_Log_Pos: 106
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 246
        Relay_Master_Log_File: data.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: system_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: 106
              Relay_Log_Space: 401
              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:

查看紅色字體部分

剩下的就本身測試下主從是否數據同步了

相關文章
相關標籤/搜索