我正在尝试向现有数据库添加一列以存储 UUID,然后检索具有该记录的 UUID 的行,但我一直得到一个空集。我将列创建为 BINARY(64) 是因为当我按照某些网站的建议尝试 BINARY(16) 时,它不足以容纳数据。这是我的创建声明:
ALTER TABLE `my_table` ADD `email_uuid` BINARY(64) NULL, ADD UNIQUE (`email_uuid`)
然后我填充它:
UPDATE `my_table` SET `email_uuid` = UUID();
为了测试它,我查询了表以获取 UUID:
mysql> select emailaddr,email_uuid FROM my_table WHERE emailaddr = 'myemail@mydomain.com';
+------------------------------------------+------------------------------------------+
| emailaddr | email_uuid |
+------------------------------------------+------------------------------------------+
| myemail@mydomain.com | a332f4d4-ddb2-11e2-88f9-80ee731fd7a1 |
+------------------------------------------+------------------------------------------+
我尝试了几种不同的方法来恢复该行:
mysql> select emailaddr,email_uuid FROM my_table WHERE email_uuid = 'a332f4d4-ddb2-11e2-88f9-80ee731fd7a1';
Empty set (0.00 sec)
mysql> select emailaddr,email_uuid FROM my_table WHERE email_uuid = '{a332f4d4ddb211e288f980ee731fd7a1}';
Empty set (0.00 sec)
mysql> select emailaddr,email_uuid FROM my_table WHERE email_uuid = BIN('{a332f4d4ddb211e288f980ee731fd7a1}');
Empty set (0.02 sec)
mysql> select emailaddr,email_uuid FROM my_table WHERE email_uuid = '61333332663464342d646462322d313165322d383866392d38306565373331666437613100000000';
Empty set (0.00 sec)
mysql> select emailaddr,email_uuid FROM my_table WHERE email_uuid = UNHEX(REPLACE('a332f4d4-ddb2-11e2-88f9-80ee731fd7a1','-',''));
Empty set (0.02 sec)
有什么我想念的吗?