最後我成功了。
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
。
我希望這是有用的人。