flink-cdc icon indicating copy to clipboard operation
flink-cdc copied to clipboard

Flink Connector mysql CDC sql-client模式下全库扫描,直到capturing到目标表,如果实例下库表比较多,会影响任务启动时效

Open EvanSole opened this issue 5 years ago • 2 comments

CREATE TABLE mysql_company_cdc ( id bigint NOT NULL, company STRING ) WITH ( 'connector' = 'mysql-cdc', 'hostname' = 'localhost', 'port' = '3306', 'username' = 'root', 'password' = '123456', 'database-name' = 'inventory', 'table-name' = 'company' );

select id,UPPER(company) from mysql_company_cdc;

启动任务后会创建一个,会全库扫描,capture目标表,如果实例下库表比较多,会影响任务启动时效 1 2

2021-01-07 20:23:11,794 INFO io.debezium.util.Threads [] - Creating thread debezium-mysqlconnector-mysql_binlog_source-snapshot 2021-01-07 20:23:11,798 INFO io.debezium.connector.mysql.SnapshotReader [] - Starting snapshot for jdbc:mysql://localhost:3306/?useInformationSchema=true&nullCatalogMeansCurrent=false&useSSL=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&connectTimeout=30000 with user 'root' with locking mode 'minimal' 2021-01-07 20:23:11,800 INFO io.debezium.connector.mysql.SnapshotReader [] - Starting snapshot for jdbc:mysql://localhost:3306/?useInformationSchema=true&nullCatalogMeansCurrent=false&useSSL=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&connectTimeout=30000 with user 'root' with locking mode 'minimal' 2021-01-07 20:23:11,803 INFO org.apache.flink.runtime.state.heap.HeapKeyedStateBackend [] - Initializing heap keyed state backend with stream factory. 2021-01-07 20:23:11,807 INFO io.debezium.connector.mysql.SnapshotReader [] - Snapshot is using user 'root' with these MySQL grants: 2021-01-07 20:23:11,808 INFO io.debezium.connector.mysql.SnapshotReader [] - GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION 2021-01-07 20:23:11,808 INFO io.debezium.connector.mysql.SnapshotReader [] - GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION 2021-01-07 20:23:11,808 INFO io.debezium.connector.mysql.SnapshotReader [] - MySQL server variables related to change data capture: 2021-01-07 20:23:11,809 INFO io.debezium.connector.mysql.SnapshotReader [] - Snapshot is using user 'root' with these MySQL grants: 2021-01-07 20:23:11,810 INFO io.debezium.connector.mysql.SnapshotReader [] - GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION 2021-01-07 20:23:11,810 INFO io.debezium.connector.mysql.SnapshotReader [] - GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION 2021-01-07 20:23:11,810 INFO io.debezium.connector.mysql.SnapshotReader [] - MySQL server variables related to change data capture: 2021-01-07 20:23:11,812 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_cache_size = 32768
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_checksum = CRC32
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_direct_non_transactional_updates = OFF
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_error_action = ABORT_SERVER
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_format = ROW
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_group_commit_sync_delay = 0
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_group_commit_sync_no_delay_count = 0
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_gtid_simple_recovery = ON
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_max_flush_queue_time = 0
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_order_commits = ON
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_row_image = FULL
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_rows_query_log_events = OFF
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_stmt_cache_size = 32768
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_transaction_dependency_history_size = 25000
2021-01-07 20:23:11,813 INFO io.debezium.connector.mysql.SnapshotReader [] - binlog_transaction_dependency_tracking

EvanSole avatar Jan 11 '21 10:01 EvanSole

可以通过缩小数据库权限避免扫描全库

-- 授予REPLICATION Slave权限
GRANT RELOAD,REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'username';

-- 授予目标库的访问权限
GRANT SELECT ON `your_single_database`.* TO 'username'@'%';

-- 刷新权限
FLUSH PRIVILEGES;

leewaiho avatar Feb 04 '21 04:02 leewaiho

Closing this issue because it was created before version 2.3.0 (2022-11-10). Please try the latest version of Flink CDC to see if the issue has been resolved. If the issue is still valid, kindly report it on Apache Jira under project Flink with component tag Flink CDC. Thank you!

PatrickRen avatar Feb 28 '24 15:02 PatrickRen