Store UUID v4 in MySQL

后端 未结 7 857
栀梦
栀梦 2020-12-08 06:58

I\'m generating UUIDs using PHP, per the function found here

Now I want to store that in a MySQL database. What is the best/most efficient MySQL field format for st

7条回答
  •  抹茶落季
    2020-12-08 07:40

    Question is about storing an UUID in MySQL.

    Since version 8.0 of mySQL you can use binary(16) with automatic conversion via UUID_TO_BIN/BIN_TO_UUID functions: https://mysqlserverteam.com/mysql-8-0-uuid-support/

    Be aware that mySQL has also a fast way to generate UUIDs as primary key:

    INSERT INTO t VALUES(UUID_TO_BIN(UUID(), true))

提交回复
热议问题