I want to transfer data from SQL Server to MariaDB. In SQL Server, the image is stored as /image/id.png. In MariaDB it should be stored as UUID.

I'm using C#. I want to convert those URLs to UUIDs. Two methods I tried:

        Guid namespaceId = new Guid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
        using (var md5 = MD5.Create())
            byte[] data = namespaceId.ToByteArray().Concat(Encoding.UTF8.GetBytes(text)).ToArray();
            byte[] hashBytes = md5.ComputeHash(data);
            hashBytes[4] = (byte)(hashBytes[4] & 0xf0 | 0x08);
            hashBytes[6] = (byte)(hashBytes[6] & 0x3f | 0x80);
            return new Guid(hashBytes);


        using (SHA256 sha256 = SHA256.Create())
            byte[] hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(text));
            Array.Resize(ref hashBytes, 16);
            guid = new Guid(hashBytes);
            return guid;

The problem is that both of them create some UUIDs that seem to be invalid according to MariaDB:

Warning 1292 Incorrect uuid value: 'd2259da7-2a8c-dfcc-3467-4ff4838a05c5' for column Media.Images.ImageGuid at row 1

How can I make sure that all of the UUIDs that I create in C# would be valid in MariaDB?

I'm using MariaDB 11.3.2.

  • UUIDs can be any combination of 16 bytes. How are you passing these in? As strings or as actual Guid values? Commented Apr 21 at 14:41
  • MariaDB implements UUID according to RFC 4122. Decode generated value and ensure that variant/timestamp/version fields contains valid data and does not contradict each other.
    – Akina
    Commented Apr 21 at 16:28
  • @Charlieface - incorrect. Random data in a hex form with separators isn't all of a sudden valid UUID - see bug report - MDEV-32112 Random incorrect uuid errors since 10.11.5 which is consistent with the documentation. You can use the UUID function in MariaDB or any other language to generate UUIDs, but random bytes aren't UUID.
    – danblack
    Commented Apr 22 at 5:06
  • @Akina, thank you for the explanation. Then I guess I should find a method to create UUIDs based on RFC 4122. Commented Apr 22 at 7:07
  • Which do you want? MD5? SHA? UUID? Don't mix them.
    – Rick James
    Commented Apr 29 at 0:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.