Is mysql auto increment safe to use as userID?

后端 未结 5 1225
刺人心
刺人心 2021-01-04 14:54

I am working on website that allows people to create profiles online. I was wondering if it is the right choice to use MySQL AUTO_INCREMENTed IDs as my user ids

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 15:39

    personally, yes I think so, up until a point. When duplicating a database table with an auto increment field, I think the field retains its max value (depending on how you duplicate it, the scenario I have in mind is mysqldump with data) so when you add a new row, it will be assigned the next ID.

    However if you were to have this running on several databases at once, and they weren't replicated, you would need some other way of generating IDs to avoid getting rows with the same ID (although I can't think of a scenario where you would do this).

    I couldn't say if it's best practise or not, but it certainly works.

提交回复
热议问题