how to know the db name for ddl in slave server by binlog?

56 Views Asked by At

In MySQL, the ddl is always statement-based replication. In the case, the binlog may not contain db name info if a ddl doesn't explicitly contain a db name such as create table table1 instead of create table db1.table1. Then how can the slave server know the right db name and do a right replication.

I don't know if the binlog contains the db name even if the ddl doesn't contain it, or the slave server don't just do replication by binlog.

1

There are 1 best solutions below

0
lant On

DDL contains db name.

You can use mysqlbinlog [options] [log_file ...] commond to read binlog file, for example:mysqlbinlog mysql-bin.000001.

I created a test_binlog table,

CREATE TABLE `test_binlog` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

the binlog like this:

enter image description here