MySQL UUID_SHORT() Function

In MySQL, the UUID_SHORT() function returns a short universal identifier (64-bit unsigned integer) that is unique under certain conditions.

The UUID_SHORT() function and the UUID() function return different values ​​and have different uniqueness properties.

UUID_SHORT() Syntax

Here is the syntax of the MySQL UUID_SHORT() function:

UUID_SHORT()

Parameters

MySQL UUID_SHORT() function does not have any parameters.

Return value

The MySQL UUID_SHORT() function returns a short universal identifier as a 64-bit unsigned integer.

This is how the return value of the UUID_SHORT() function is constructed:

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

The value returned from UUID_SHORT() is unique when the following conditions are met :

  • The server_id value between 0 and 255 and is unique within your set of source and replica servers
  • You don’t set the server host’s system time between mysqld restarts
  • You average calls of UUID_SHORT() is less than 16 million per second

UUID_SHORT() Examples

Here is the basic usage of MySQL UUID_SHORT() function.

SELECT UUID_SHORT();
+-------------------+
| UUID_SHORT()      |
+-------------------+
| 99737540025647105 |
+-------------------+