go-mysql-org / go-mysql

a powerful mysql toolset with Go
MIT License
4.52k stars 967 forks source link

Replication QUERY_EVENT issue #890

Closed zhanghaiyang9999 closed 1 month ago

zhanghaiyang9999 commented 1 month ago

If I had 2 schemas, named test001 and tpcc. They have one same name(say t2) table, when I change the table t2 of tpcc, the query_event returns the schema name is test001. can reproduce this issue stably with Mysql5.x or Mysql 8.x

replication.QUERY_EVENT event := ev.Event.(*replication.QueryEvent) dbname := string(event.Schema) //the dbname is test001 sqlstr := string(event.Query) //the sqlstr is "ALTER TABLE tpcc.t2 ADD COLUMN desc10 VARCHAR(45) NULL AFTER desc9;"

lance6716 commented 1 month ago

it's the design of MySQL binlog replication. https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_replication_binlog_event.html#sect_protocol_replication_event_query You can find some material to learn about it.

zhanghaiyang9999 commented 1 month ago

it's the design of MySQL binlog replication. https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_replication_binlog_event.html#sect_protocol_replication_event_query You can find some material to learn about it.

Thanks! But it's a strange design.

lance6716 commented 1 month ago

it's the design of MySQL binlog replication. https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_replication_binlog_event.html#sect_protocol_replication_event_query You can find some material to learn about it.

Thanks! But it's a strange design.

I remember it means the current database this session is on (USE db). So if the query doesn't specify the database name this field should act as the default value.