Skip to content

Instantly share code, notes, and snippets.

@jasonhancock
Created August 17, 2012 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonhancock/3382454 to your computer and use it in GitHub Desktop.
Save jasonhancock/3382454 to your computer and use it in GitHub Desktop.
Inerting/selecting GUIDs into/from MySQL
mysql>CREATE TABLE jive (uuid CHAR(16) BINARY);
Query OK, 0 rows affected (0.02 sec)
mysql> select UUID();
+--------------------------------------+
| UUID() |
+--------------------------------------+
| 519718a1-e8ab-11e1-8803-080027e1c419 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO jive(uuid) VALUES(UNHEX(REPLACE('519718a1-e8ab-11e1-8803-080027e1c419', '-', '')));
Query OK, 1 row affected (0.00 sec)
mysql> SELECT HEX(uuid) FROM jive;
+----------------------------------+
| HEX(uuid) |
+----------------------------------+
| 519718A1E8AB11E18803080027E1C419 |
+----------------------------------+
1 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment