最后我成功了。
1.-用户名、密码和数据库名称必须相同。
2.-授予用户远程连接到另一台服务器的权限。您可以按照本指南进行操作。
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');
要直接执行结果,可以--print
通过 option更改选项--execute
。
我希望它对某人有用。