content_image/805424.jpg
uniqueness properties. The value of UUID_SHORT()  is guaranteed to be unique if the following conditions hold: 

•The server_id  value of the current server is between 0 and 255 and is unique among your set of source and replica servers 

•You do not set back the system time for your server host between mysqld  restarts 

•You invoke UUID_SHORT()  on average fewer than 16 million times per second between mysqld restarts 

The UUID_SHORT()  return value is constructed this way: 

(server_id & 255) << 56 + (server_startup_time_in_seconds << 24) + incremented_variable++; 

mysql> SELECT UUID_SHORT(); -> 92395783831158784 

<img src='content_image/805424.jpg'>

## Note 

UUID_SHORT()  does not work with statement-based replication. 

• UUID_TO_BIN( string_uuid ) , UUID_TO_BIN( string_uuid , swap_flag ) 

Converts a string UUID to a binary UUID and returns the result. (The IS_UUID()  function description lists the permitted string UUID formats.) The return binary UUID is a VARBINARY(16)  value. If the UUID argument is NULL , the return value is NULL . If any argument is invalid, an error occurs. 

UUID_TO_BIN()  takes one or two arguments: 

•The one-argument form takes a string UUID value. The binary result is in the same order as the string argument. 

•The two-argument form takes a string UUID value and a flag value: 

•If swap_flag  is 0, the two-argument form is equivalent to the one-argument form. The binary result is in the same order as the string argument. 

•If swap_flag  is 1, the format of the return value differs: The time-low and time-high parts (the first and third groups of hexadecimal digits, respectively) are swapped. This moves the more rapidly varying part to the right and can improve indexing efficiency if the result is stored in an indexed column. 

Time-part swapping assumes the use of UUID version 1 values, such as are generated by the UUID() function. For UUID values produced by other means that do not follow version 1 format, time-part swapping provides no benefit. For details about version 1 format, see the UUID()  function description. 

Suppose that you have the following string UUID value: 

mysql> SET @uuid = ’6ccd780c-baba-1026-9564-5b8c656024db’; 

To convert the string UUID to binary with or without time-part swapping, use UUID_TO_BIN() : 

mysql> SELECT HEX(UUID_TO_BIN(@uuid)); +----------------------------------+ | HEX(UUID_TO_BIN(@uuid)) | 

