我正在尝试使用以下命令双向同步两个数据库(一个本地和一个远程):
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的理解不正确。
我希望你能帮助我。谢谢。
最佳答案
终于我成功了。
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');
要直接执行结果,可以通过选项
--print
更改选项--execute
。我希望它对某人有用。
关于mysql - 与pt-table-sync双向同步,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19262619/