0

I have written a python program to parse mysql binlog. In the Query Event, there is a Q_CHARSET_CODE which indicate what character set is used for the logged query. This indicated that the logged query is based on the client connection character set.

But in Row Base Events, the Insert Row, Update Row, and Delete Row, I cannot find out what character set is used in the log for each corresponding column? Was is based on the client connection character set or it is based on the column character set in the Information Schema.

2
  • does the code describe the this adequately. I think the number are evident from the information schema or SHOW commands related to charset/collation. Commented Jul 12 at 6:58
  • 2
    When you insert or update a column, the stored data is always in the column's character set Commented Jul 12 at 7:37

1 Answer 1

2

The character set of a row image in row based events is always the character set(s) used for the columns of that row. You can get this from INFORMATION_SCHEMA.COLUMNS (which has COLLATION_NAME, not character set name, but since each collation belongs to only one character set, you can look it up in INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY.

Note that it's possible for multiple columns in a table to have different character sets. The character set at the table level is just the default.

The character set used when the client updated that row is not needed, because in row based events, the replica isn't going to re-execute the statement that updated, it's only going to copy the row image verbatim.

It's like buying a slice of cake at the coffee shop. You don't need to know what temperature was used to bake that cake. It's already baked, so just eat it. :-)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I am curious what character set will be used in the Annotation event. This is not important, I think I can find out. Initially, I thought when in mysqldump, using --no-defaults, all dumped SQL was in utf8. Then I found out that they are in the character set in according to the connection of that SQL.
Annotate events are a MariaDB-specific enhancement, not MySQL. github.com/MariaDB/server/blob/main/sql/log_event.h#L709

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.