# Use MongoDB's ObjectIds as MySQL Primary Keys?

**URL:** <https://forums.percona.com/t/use-mongodbs-objectids-as-mysql-primary-keys/5752>\
**Category:** Other MySQL® Questions\
**Created:** [July 19, 2017, 8:02pm UTC](https://forums.percona.com/t/use-mongodbs-objectids-as-mysql-primary-keys/5752 "2017-07-19T20:02:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktwalrus](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ktwalrus/32/1178_2.png) [@ktwalrus](https://forums.percona.com/u/ktwalrus)\
**Post date:** [July 19, 2017, 8:02pm UTC](https://forums.percona.com/t/use-mongodbs-objectids-as-mysql-primary-keys/5752/1 "2017-07-19T20:02:09Z")

</div>

I’m thinking of using MongoDB’s ObjectIds for my primary keys in MySQL. ObjectIds are stored as BINARY(12) and I think they are very unlikely to have a duplicate primary key globally. I want to avoid the performance issues with using UUID() which are BINARY(16), but require rearranging the order of the bytes for good performance. And, ObjectIds are 32-bits shorter. I was thinking of using short UUIDs as primary keys since they fit in 64 bits but I think they might have too high a chance of generating a duplicate.

I am in the process of shard’ing a database that currently uses BIGINT auto-increment primary keys and now needs the primary keys to be globally unique since they may be generated from a lot of different shards/mysql servers.

Is this a good idea? Or, is there some performance hit that the database will take because of the choice of BINARY(12) primary keys based on MongoDB’s ObjectIds?
