Skip to content

Instantly share code, notes, and snippets.

@Wector11211
Wector11211 / minecraft-offline-uuid.sql
Created August 26, 2023 08:56
Generate an offline minecraft UUID v3 based on the case sensitive player name
CREATE OR REPLACE FUNCTION generate_offline_uuid(
username_p VARCHAR(20)
) RETURNS VARCHAR(36) BEGIN
DECLARE uuid_bytes VARCHAR(36);
SELECT MD5(CONCAT('OfflinePlayer:', username_p)) INTO uuid_bytes;
SELECT INSERT(uuid_bytes, 13, 2, HEX(CONV(SUBSTR(uuid_bytes, 13, 2), 16, 10) & 0x0f | 0x30)) INTO uuid_bytes;
SELECT INSERT(uuid_bytes, 17, 2, HEX(CONV(SUBSTR(uuid_bytes, 17, 2), 16, 10) & 0x3f | 0x80)) INTO uuid_bytes;
RETURN (SELECT LCASE(CONCAT_WS('-',
SUBSTR(uuid_bytes, 1, 8),
SUBSTR(uuid_bytes, 9, 4),