public static void main(String[] args) throws Exception {
MySqlSource<String> mySqlSource = MySqlSource.<String>builder() .hostname("localhost") .port(3306) .databaseList("test") // set captured database, If you need to synchronize the whole database, Please set tableList to ".*". .tableList("test.user") // set captured table .username("root") .password("123456") .serverTimeZone("America/Danmarkshavn") .deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String .build();
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
1.Caused by: org.apache.flink.table.api.ValidationException: The MySQL server has a timezone offset (0 seconds ahead of UTC) which does not match the configured timezone Asia/Shanghai. Specify the right server-time-zone to avoid inconsistencies for time-related fields.
这个因为没有给mysql cdc任务指定时区,可以使用如下命令查看mysql的时区
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | UTC | | time_zone | SYSTEM | +------------------+--------+ 2 rows in set (0.02 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2024-08-17 15:29:48 | +---------------------+ 1 row in set (0.00 sec)
假设mysql的时区是UTC,则需要指定和mysql时区一样的时区配置,如下
1 2 3 4 5 6 7 8 9 10 11
MySqlSource<String> mySqlSource = MySqlSource.<String>builder() .hostname("localhost") .port(55000) .databaseList("default") // set captured database, If you need to synchronize the whole database, Please set tableList to ".*". .tableList("default.test") // set captured table .username("root") .password("123456") .serverTimeZone("America/Danmarkshavn") .deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String .build();
2.Caused by: org.apache.flink.util.FlinkRuntimeException: Cannot read the binlog filename and position via ‘SHOW MASTER STATUS’. Make sure your server is correctly configured