# pt-table-sync two databases on the same mysql server?

**URL:** <https://forums.percona.com/t/pt-table-sync-two-databases-on-the-same-mysql-server/3345>\
**Category:** Percona Toolkit\
**Created:** [March 18, 2014, 7:26pm UTC](https://forums.percona.com/t/pt-table-sync-two-databases-on-the-same-mysql-server/3345 "2014-03-18T19:26:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiku](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@kiku](https://forums.percona.com/u/kiku)\
**Post date:** [March 18, 2014, 7:26pm UTC](https://forums.percona.com/t/pt-table-sync-two-databases-on-the-same-mysql-server/3345/1 "2014-03-18T19:26:21Z")

</div>

Hi,

is it possible with pt-table-sync to sync one table between two databases (databases have same structure) which are on the same localhost?

Example: I have first database “data1” with table “tbl1” and second database “data2” with table “tbl2” on the same mysql server and I want to have “tbl2” to be equal to “tbl1” if I make some changes to “tbl1”.

Best regards,  
Chris

---

<div class="post-metadata">

**Author:** ![niljoshi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/niljoshi/32/16889_2.png) [@niljoshi](https://forums.percona.com/u/niljoshi)\
**Post date:** [March 25, 2014, 4:28am UTC](https://forums.percona.com/t/pt-table-sync-two-databases-on-the-same-mysql-server/3345/2 "2014-03-25T04:28:37Z")

</div>

Hi,

You can try with --bidirectional option. Check here for more details. [url][pt-table-sync — Percona Toolkit Documentation](http://www.percona.com/doc/percona-toolkit/2.2/pt-table-sync.html#bidirectional-syncing%5B/url%5D)

With that option, you can give 2 individual hosts details for sync. i.e

mysql\> select \* from data1.tbl1;  
±—±----------+  
| id | name |  
±—±----------+  
| 1 | nilnandan |  
| 2 | joshi |  
| 3 | ramesh |  
±—±----------+  
3 rows in set (0.00 sec)

mysql\> select \* from data2.tbl2;  
±—±----------+  
| id | name |  
±—±----------+  
| 1 | nilnandan |  
| 2 | joshi |  
±—±----------+  
2 rows in set (0.00 sec)

shell$ pt-table-sync --bidirectional --print --conflict-column=“id” --conflict-comparison=“newest” h=localhost,u=root,p=root,D=data1,t=tbl1 h=localhost,u=root,p=root,D=data2,t=tbl2  
/_localhost_/ INSERT INTO `data2`.`tbl2`(`id`, `name`) VALUES (‘3’, ‘ramesh’);  
shell$

Here, 1st host will be reliable server and 2nd which is lacking data. You can also do vice-versa. I would suggest to check first with --print option on some stage servers and then try with prod dbs.
