[英]Replicate tables from different database of same mysql server
我有一台服務器有2個數據庫,我想將多個表從一個數據庫復制到另一個數據庫。 目的是我們使用與項目中使用的相同的用戶表。
就像在其他表中使用InnoDB和用戶表的外鍵一樣,我選擇了一種復制方式。
為此,我對my.cnf進行了更改
master-user=root
server-id = 2
replicate-rewrite-db = dou->jobs
replicate-do-table = jobs.auth\_user
replicate-wild-do-table = jobs.geo\_%
replicate-do-table = jobs.user\_profile
replicate-same-server-id = 1
report-host = master-is-slave
binlog-do-db = dou
log-bin
從binlog-do-db
同步表並啟動slave error.log后,出現以下幾行:
111112 15:10:22 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='localhost', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='localhost', master_port='3306', master_log_file='mysql-bin.000074', master_log_pos='106'.
111112 15:10:36 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000074' at position 106, relay log '/var/log/mysql/dell-relay-bin.000001' position: 4
111112 15:10:36 [Note] Slave I/O thread: connected to master 'root@localhost:3306',replication started in log 'mysql-bin.000074' at position 106
似乎在此步驟中一切正常,並且show slave status
顯示任何錯誤。
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000074
Read_Master_Log_Pos: 814
Relay_Log_File: dell-relay-bin.000002
Relay_Log_Pos: 959
Relay_Master_Log_File: mysql-bin.000074
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: jobs.user\_profile,jobs.auth\_user
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: jobs.geo\_%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 814
Relay_Log_Space: 1113
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:
1 row in set (0.00 sec)
ERROR:
No query specified
問題是主機更改不會影響從機,但會影響從機狀態。
感謝您為解決該問題提供的幫助。
出於興趣,視圖會做什么?
我真的不認為將mysql的相同實例上的復制運行到相同的實例中不是一個好主意。
您可能想調查服務器硬件是否有問題的另一種方法是,在同一台計算機上的多個端口上運行mysql的多個實例,這可能有助於您實現所需的功能。 這是我在測試環境中用於模擬主數據庫故障和從數據庫升級的內容。
我不會告訴您將表復制到相同的DB是個壞主意,因為IO會增加幾倍。
從站不會更新,因為主服務器和從服務器的server-id相同。 通常,slave會忽略具有相同服務器ID的更新。
將復制相同服務器ID添加到my.cnf。 復制相同服務器ID文檔
例如,在許多情況下,您可以實現更多優化。 DB1復制到DB2(同一服務器)。 從那里DB2僅存儲了長達1周的數據。 刪除所有早於1周的數據(在db2上)。 在這樣的設置中,例如高流量的db服務器,如果您服務器大部分時間從服務器讀取數據,則您需要盡可能干凈的同一台服務器上的雙數據庫設置使用服務器中的“較少”資源數據庫。 我有這樣的設置,但是我使用了4個不同的服務器。 服務器1)3天。 服務器2)30天。 服務器3)2個月,服務器4從頭開始所有數據。 (服務器4主要用於獲取非常舊的寄存器,但使用的很少。對不起,我的英語霸王,我想我對您可以在哪里提出了意見,應該在同一服務器上使用db復制來減少內存使用和cpu的使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.