Skip to content

dump VARBINARY and BIT values as escaped binary strings - #554

Merged
deitch merged 1 commit into
databacker:mainfrom
jayhemnani9910:fix/dump-varbinary-bit
Nov 19, 2026
Merged

deitch merged 1 commit into
databacker:mainfrom
jayhemnani9910:fix/dump-varbinary-bit

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

VARBINARY and BIT columns scan into []byte, which RowBuffer has no case for, so they hit the default fmt.Fprintf(&b, "'%s'", value) and the dump gets '&' followed by the raw, unescaped bytes. The dump reports success, but the restore fails as soon as a value contains a quote byte:

CREATE TABLE places (id INT PRIMARY KEY, token_hash VARBINARY(32), flags BIT(8));
INSERT INTO places VALUES (1, UNHEX(SHA2('x',256)), b'00100111'), (2, NULL, b'00000001');

mysql-backup dump --include shop, then restore --database shop:shop2:

Error 1064 (42000): You have an error in your SQL syntax; ... near '\x01')' at line 1

Without such a byte it restores, but every value has a leading &.

*[]byte now gets the same _binary '...' form as sql.RawBytes, and a NULL stays NULL. With the change the table above restores with the same HEX(token_hash) and HEX(flags) as the source (MySQL 8.4).

Added table_test.go (a value with NUL, quote and backslash bytes, a BIT 0x27, and NULL); it fails without the change. go test ./pkg/... passes; I didn't run the docker integration test.

@deitch deitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solid. mysql-backup has been around for years, I am surprised we never came across this before. But I do appreciate your finding and fixing it, and including a nice test as well.

Do you mind moving it up in the file? Other than that, ready to go.

Comment thread pkg/database/mysql/table.go Resolved
Signed-off-by: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com>
@deitch
deitch merged commit 12449a2 into databacker:main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants