1/2/2024 0 Comments Mysql uuid functionsIf installed on your machine, you can make use of the php-uuid package.Īn example code (which can be used in your application as is) can be found here: You should use V4 UUID instead of V1 if you need your UUID to be unpredictable.Īlso, note that composing for example 4x4 byte random values may not be the same as creating a 16 byte random value.Īs always with crypto and randomness: I would disadvise from implementing your own UUID::V4 routine. In V4 there is no such mechanism, although practically you don't need to worry too much about clashes either :) In fact, V1 UUID is more fit than V4 if you use the UUID just as a table ID - because it uses MAC-address and time stamp to prevent clashes. You will never be able to have as many entries in your database, as the theoretical limit of 16 bytes allows. Your concern, that "most of the UUID is useless and is wasting space" is inherent to the size of the data type. I do not and will not be performing merging, synchronization, or other operations that require a GUID that contains the MAC address.I would prefer avoiding third-party packages/libraries.I am using a shared hosting plan with command-line access, but cannot modify the existing MySQL installation.If not, is it acceptable to generate a custom UUID within PHP (as above) that does not conform to a specification? Is there a preferred/recommended way to generate a Version 4 or Version 5 UUID within a MySQL query? Here, the first 8 characters are identical for the same user. In addition, if the MAC address never changes, most of the UUID is useless and is wasting space.Īs an experiment, I wrote a custom UUID-generator in PHP: public static function GenerateUUID() However, I am hesitant in using Version 1 because of these similarities (and the fact that the MAC address will never change, in my case). I understand that UUID Version 1 uses a timestamp and hardware MAC address to generate the UUID. When generating UUID's via MySQL's UUID() function, they are extremely similar to one another: | uuid |Īs you can see, only the first 8 characters and the 11th and 12th are different. I recently switched from using an auto-incremented integer to a UUID as a primary key for some of my tables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |