'Why is restore to a mariadb instance with log-bin enabled not working to database not in binlog_do_db and UNIQUE_CHECKS=0?

There is a mariadb version 10.7 instance running in Kubernetes.
Recently log-bin was added to the server.cnf.
The restore scripts stopped working for any database not in binlog_do_db with no error.
The problem seems to be related to: SET UNIQUE_CHECKS=0;SET FOREIGN_KEY_CHECKS=0;.
Also the mariadb log contains no errors or messages related to the restore.
Any ideas greatly appreciated.
Thank you.

server.cnf

[mariadb]
log-bin
server_id=1
log-basename=1
binlog-format=mixed
binlog_do_db=db1
binlog_do_db=db2

example.sql

DROP DATABASE if EXISTS test;
CREATE DATABASE test;
USE test;

CREATE TABLE IF NOT EXISTS `test` (
    `test` INT(11) NULL DEFAULT NULL
);

SET UNIQUE_CHECKS=0;
SET FOREIGN_KEY_CHECKS=0;

INSERT INTO test VALUES (1);

SET FOREIGN_KEY_CHECKS=1;
SET UNIQUE_CHECKS=1;

SELECT * FROM test;

-- if binlog_do_db contains test (or log-bin is not used), the insert works.
-- if log-bin is used and binlog_do_db doesn't contain test, the insert will silently fail.

Edit: Added mariadb version 10.7. Same problem with 10.8-rc



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source