Home  >  Q&A  >  body text

数据库设计 - MySQL数据库主键问题

前几天在项目组里,总监建议把所有数据表的主键设为字符串类型(UUID),由应用程序维护数据表的主键,问下这个主要是出于什么方面的考虑呢???
P.S. 我们用的MySQL数据库,存储引擎用的InnoDB,看了很多DBA的文章建议是说InnoDB类型的表最好是使用自增主键...

高洛峰高洛峰2743 days ago854

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 16:21:42

    UUID generates primary keys to avoid duplication of primary keys, and the program is easy to maintain. @wangcw explains it very well. As for the disadvantages, I have not encountered them yet due to limited experience

    reply
    0
  • 黄舟

    黄舟2017-04-17 16:21:42

    As far as I understand, the advantages of using UUID are low repeatability, convenient automatic generation, and there is no need to consider the problem of repeated insertion failure of the primary key;
    The reason why it is not recommended to use UUID: After the data volume reaches a certain value, index maintenance is very inconvenient, and the database performance is greatly reduced. Fragmentation organization also has a certain impact.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 16:21:42

    If you use UUID, you have to maintain the primary key through the application. Isn’t this very cumbersome...

    reply
    0
  • Cancelreply