Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No field name in TABLE_MAP_EVENT? #24

Closed
e7868a opened this issue May 21, 2014 · 6 comments
Closed

No field name in TABLE_MAP_EVENT? #24

e7868a opened this issue May 21, 2014 · 6 comments

Comments

@e7868a
Copy link

e7868a commented May 21, 2014

Hi.

This is not a problem about 'mysql-binlog-connector-java'.

I just find out that there is no field name in TableMapEventData. how can i regenerate the SQL from WRITE_ROWS,UPDATE_ROWS,DELETE_ROWS.or there is other method to update slave mysql database?

Thanks for help.

@shyiko
Copy link
Owner

shyiko commented May 21, 2014

Hi Jian,

What do you mean by "field name"?

It's not possible to "regenerate the SQL from WRITE_ROWS,UPDATE_ROWS,DELETE_ROWS". If you need to know original SQL you must either use SBR (binlog_format=STATEMENT) or turn on binlog_rows_query_log_events (available starting from MySQL 5.6.2). In case of the latter you would also have to add custom RowsQuery event data deserializer.

@rtreffer
Copy link
Contributor

Fields (SQL columns) are referenced by position within the table and not name.

CREATE TABLE a ( b BIGINT, c VARCHAR(64) );
INSERT INTO a VALUES (3, '?');

This will create a write row event for table a and it will contain the columns 0 and 1. (I'm not sure if it's 0 or 1 based atm).

To reconstruct field names you'd have to get the schema of the master first.

@shyiko
Copy link
Owner

shyiko commented May 21, 2014

Thanks, Rene.

Jian, to get the list of columns you could use something similar to:

Connection connection = ...
DatabaseMetaData metaData = connection.getMetaData();
ResultSet tableResultSet = metaData.getTables(null, "public", null, new String[]{"TABLE"});
try {
    while (tableResultSet.next()) {
        String tableName = tableResultSet.getString("TABLE_NAME");
        ResultSet columnResultSet = metaData.getColumns(null, "public", tableName, null);
        try {
            while (columnResultSet.next()) {
                String columnName = columnResultSet.getString("COLUMN_NAME");
                ...
            }
        } finally {
            columnResultSet.close();
        }
    }
} finally {
    tableResultSet.close();
}

@e7868a
Copy link
Author

e7868a commented May 23, 2014

Thanks guys. That helps me a lot. now i get understand.
I will close the Issue Now.:)

@spccold
Copy link

spccold commented Nov 7, 2018

this dosen't work when mysql-binlog-connector-java have a large lag, because mysql binlog is old, but metadata is latest

@ahmedahamid
Copy link
Contributor

ahmedahamid commented Dec 11, 2018

Column names have been recently added to the binlog in MySQL 8.0.1, subject to some non-default configuration. With PR #251 now checked in, it is possible to read column names if you set binlog_row_metadata to FULL. More details about the newly added metadata is right here.

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

No branches or pull requests

5 participants