[MDEV-23802] Add a new command line option to mysqlbinlog, to choose between my_b_write_quoted() and pure HEX notation Created: 2020-09-24  Updated: 2023-12-11

Status: Confirmed
Project: MariaDB Server
Component/s: Replication
Fix Version/s: 11.2

Type: Task Priority: Minor
Reporter: Sujatha Sivakumar (Inactive) Assignee: Brandon Nesterenko
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Add a new command line option to mysqlbinlog, to choose between my_b_write_quoted() and pure HEX notation.

Create a table which has fields of type BLOB or GEOMETRY. Have binary log format as 'row'.

For example:

mysql> create table t(f blob) engine=innodb;
Query OK, 0 rows affected (0.07 sec)
mysql> insert into t values (0x000000000101000000000000000000F03F000000000000F03F);
Query OK, 1 row affected (0.01 sec)

Try to print the binarylog by using "mysqlbinlog -v"

### INSERT INTO `test`.`t`
### SET
###   @1='\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00�?\x00\x00\x00\x00\x00\x00�?'
# at 574
#200923 15:31:19 serve

The BLOB field value gets printed in semi hex format. Hence when the above
'mysqlbinlog verbose' query is fed back to 'mysql client' by replacing '@1' with appropriate field name it inserts entirely a new value. Please find the following output.

mysql> insert into t values ('\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00�?\x00\x00\x00\x00\x00\x00�?');
Query OK, 1 row affected (0.05 sec)
mysql> select * from t;
+-------------------------------------------------------------------------+
| f                                                                       |
+-------------------------------------------------------------------------+
|              �?      �?                                                 |
| x00x00x00x00x01x01x00x00x00x00x00x00x00x00x00�?x00x00x00x00x00x00�?     |
+-------------------------------------------------------------------------+
2 rows in set (0.00 sec)

Suggested fix by Bar is mentioned below:

Make to row event decoder to print data in pure HEX format.
For ex:

### INSERT INTO `test`.`t`
### SET
###   @1=0x0000000001010000000000000000.....;

With the above the 'mysqlbinlog verbose query' can be given as input to mysql client.

Add a new command line option to mysqlbinlog, to choose between `my_b_write_quoted() ` and pure HEX notation: 0xAABBCC. `my_b_write_quoted()` prints control character using escape sequences, and other characters - literally. This is not something the parser can understand. It's supposed to be read by a human. Add a new function, to print ALL characters using HEX notation. Both control and non-control.



 Comments   
Comment by Anel Husakovic [ 2023-12-11 ]

I tried to recreate the problem on 11.4, but I don't see the semi-hex format with mariadb-binlog -v <binlogfile

SET @@session.lc_time_names=0/!/;
SET @@session.collation_database=DEFAULT/!/;
create table t(t blob)
/!/;
# at 513
#231206 11:46:05 server id 1  end_log_pos 555 CRC32 0xf79f5ff7 	GTID 0-1-2
/!100001 SET @@session.gtid_seq_no=2//!/;
START TRANSACTION
/!/;
# at 555
#231206 11:46:05 server id 1  end_log_pos 697 CRC32 0x818536b3 	Query	thread_id=5	exec_time=0	error_code=0	xid=0
SET TIMESTAMP=1701859565/!/;
insert into t values (0x000000000101000000000000000000F03F000000000000F03F)
/!/;

Generated at Thu Feb 08 09:25:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.