ddl 方式
package com.jq.wc
import org.apache.flink.streaming.api.scala._
import org.apache.flink.table.api.Table
import org.apache.flink.table.api.scala._
object MysqlSource {
def main(args: Array[String]): Unit = {
val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
val tableEnv: StreamTableEnvironment = StreamTableEnvironment.create(env)
val createTableSql = """CREATE TABLE story (
| id BIGINT,
| title STRING
|) WITH (
| 'connector.type' = 'jdbc',
| 'connector.url' = 'jdbc:mysql://localhost:3306/story',
| 'connector.table' = 'story',
| 'connector.username' = 'root',
| 'connector.password' = 'root'
|)""".stripMargin
tableEnv.sqlUpdate(createTableSql)
val table: Table = tableEnv.sqlQuery("select id, title from story")
table.printSchema()
table.toAppendStream[(Long,String)].print("sql")
env.execute("table api test")
}
}