-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Print binary data as hex in the mysql client #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Example: mysql> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.05 sec) mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 1'); Query OK, 1 row affected (0.01 sec) mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 2'); Query OK, 1 row affected (0.01 sec) mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 3'); Query OK, 1 row affected (0.01 sec) mysql> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | � �`��w���}4 | test 1 | | "3l��`��w���}4 | test 2 | | $����`��w���}4 | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) mysql> select * from t1\G *************************** 1. row *************************** id: 0x20D7170ACB6011E6BD77AC87A3027D34 name: test 1 *************************** 2. row *************************** id: 0x22336CBDCB6011E6BD77AC87A3027D34 name: test 2 *************************** 3. row *************************** id: 0x24A2AD93CB6011E6BD77AC87A3027D34 name: test 3 3 rows in set (0.00 sec) mysql> select * from t1 where id=0x22336CBDCB6011E6BD77AC87A3027D34; +------------------+--------+ | id | name | +------------------+--------+ | "3l��`��w���}4 | test 2 | +------------------+--------+ 1 row in set (0.00 sec)
Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment: |
I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it. |
Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow |
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
Print binary data as hex literals.
The result is that this doesn't break my terminal if I select a binary column and this allows me
to copy-paste the output to the were clause of my next query.