2013-10-09 101 views
0

我想雙向同步兩個數據庫使用命令(一個是本地,一個遠程):雙向同步與PT-表同步

pt-table-sync --print --bidirectional --conflict-column * 
--conflict-comparison newest --databases my_db 
h=localhost,u=root,p=my_pass, h=ip_remote_server 

顯示錯誤:

DBI connect(';host=Aplicaciones;mysql_read_default_group=client','',...) 
failed: Unknown MySQL server host 'Aplicaciones' (2) at 
/usr/bin/pt-table-sync line 2208 

他們數據庫有兩個相同的用戶名和密碼,如here

我沒有正確的理解documentation

我希望你能幫助我。謝謝。

回答

2

最後我成功了。

1.-用戶名,密碼和數據庫名稱必須相同。

2:授予權限的用戶可以遠程連接到另一臺服務器。你可以關注this guide

3.-運行以下腳本:

服務器本地:

GRANT SELECT, REPLICATION CLIENT, SHOW DATABASES, SUPER, PROCESS ON *.* TO 'your_user'@'localhost' IDENTIFIED BY 'your_password'; 

服務器遠程:

GRANT SELECT, REPLICATION CLIENT, SHOW DATABASES, SUPER, PROCESS ON *.* TO 'your_user'@'your_real_ip_local' IDENTIFIED BY 'your_password'; 

4.-案例來進行測試:表「顏色「

服務器本地:

+----------+--------+--------+---------+---------------------+ 
| id_color | name | status | deleted | date_register  | 
+----------+--------+--------+---------+---------------------+ 
|  1 | Negro |  1 |  0 | 2012-01-26 00:35:19 | 
|  2 | Blue |  1 |  0 | 2012-01-26 00:35:19 | 
|  3 | Gray |  1 |  0 | 2012-01-26 00:35:19 | 
|  4 | Silver |  1 |  0 | 2012-01-26 00:35:19 | 
|  5 | Tan |  1 |  0 | 2012-01-26 00:35:19 | 
|  6 | White |  1 |  0 | 2012-04-05 14:14:37 | 
+----------+--------+--------+---------+---------------------+ 

服務器遠程:

+----------+----------+--------+---------+---------------------+ 
| id_color | name  | status | deleted | date_register  | 
+----------+----------+--------+---------+---------------------+ 
|  1 | Black |  1 |  0 | 2012-01-26 00:35:19 | 
|  2 | Blue  |  1 |  0 | 2012-01-26 00:35:19 | 
|  3 | Gray  |  1 |  0 | 2012-01-26 00:35:19 | 
|  4 | Silver |  1 |  0 | 2012-01-26 00:35:19 | 
|  5 | Tan  |  1 |  0 | 2012-01-26 00:35:19 | 
|  6 | White |  1 |  0 | 2012-04-05 14:14:37 | 
|  7 | Amarillo |  1 |  0 | 2013-10-19 01:25:08 | 
+----------+----------+--------+---------+---------------------+ 

5.-運行命令:

$ pt-table-sync --print --bidirectional --conflict-column 'name' --conflict-comparison newest h=ip_your_server_remote,u=your_user,p=your_password,D=your_db,t=color h=localhost 

6.-結果:

/*ip_your_server_remote*/ UPDATE `your_db`.`color` SET `name`='Negro', `status`='1', `deleted`='0', `date_register`='2012-01-26 00:35:19' WHERE `id_color`='1' LIMIT 1; 
/*localhost*/ INSERT INTO `your_db`.`color`(`id_color`, `name`, `status`, `deleted`, `date_register`) VALUES ('7', 'Amarillo', '1', '0', '2013-10-19 01:25:08'); 

直接執行的結果,你可以通過選項--execute更改選項--print

我希望這是有用的人。