0

我正在尝试使用以下命令双向同步两个数据库(一个本地数据库和一个远程数据库):

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

他们的数据库用户名和密码与这里所说的一样

我不正确理解文档

我希望你能帮助我。谢谢。

4

1 回答 1

2

最后我成功了。

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

我希望它对某人有用。

于 2013-10-19T06:16:04.343 回答