connector 如下:
'connector' = 'jdbc',
'url' = 'jdbc:mysql://localhost:3306/dbname?characterEncoding=utf8&useSSL=false',
'table-name' = 'tablename',
// 'driver' = 'com.mysql.cj.jdbc.Driver',
'username' = 'username',
'password' = 'pwd'
1、useSSL=false:解决 ssl 问题
2、characterEncoding=utf8:解决中文乱码问题
3、驱动不一致会导数数据无法写入,注释驱动,让flink自动推断即可
mysql 建表语句
CREATE TABLE `sku_test_upsert` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '库存id(itemID)',
`price` decimal(10,0) DEFAULT NULL COMMENT '价格',
`sku_name` varchar(200) DEFAULT NULL COMMENT 'sku名称',
`category3_id` bigint(20) DEFAULT NULL COMMENT '三级分类id(冗余)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='库存单元表'
flink sql source jdbc 错误的建表语句
CREATE TABLE sku_test_upsert(
id bigint ,
price bigint ,
sku_name STRING ,
category3_id bigint,
PRIMARY KEY(id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:mysql://localhost:3306/dbname?useSSL=false',
'table-name' = 'sku_test_upsert',
'username' = 'username',
'password' = 'pwd'
)
错误的地方是price 字段的数据类型是bigint ,要改成decimal(10,2) 类型才能正常查询数据,最坑的是没有任何的报错信息提示
备注:要非常关注字段的数据类型映射是否正确,这个可能会影响能否查询数据的关键,没提示任何报错,此点非常坑
flink sql source jdbc 正确的建表语句:
CREATE TABLE sku_test_upsert(
id bigint ,
price decimal(10,2) ,
sku_name STRING ,
category3_id bigint,
PRIMARY KEY(id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:mysql://localhost:3306/dbname?useSSL=false',
'table-name' = 'sku_test_upsert',
'username' = 'username',
'password' = 'pwd'
)