Source: https://dev-docs.yueshu.com.cn/v5.3.2/utilities/exchange/config/sources/jdbc/ Documentation version: v5.3.2 # JDBC 配置 本文介绍从 JDBC 数据源导入数据的配置项。关于完整配置文件和配置项的信息,请参见[数据导入配置](https://dev-docs.yueshu.com.cn/v5.3.2/utilities/exchange/config/)。 ## 数据源配置 []() 下表列出了 JDBC 数据源特定的配置项: | 选项 | 描述 | 类型 | 是否必选 | 默认值 | `type` | 数据源的类型。设置为`"jdbc"`。 | String | 是 | 无 | `url` | 数据源的 JDBC URL。 | String | 是 | 无 | `driver` | JDBC 驱动类名。对于 MySQL,需设置为`"com.mysql.cj.jdbc.Driver"`。对于 PostgreSQL,需设置为`"org.postgresql.Driver"`。 对于其他数据库,请根据 JDBC 驱动的版本进行设置。 | String | 是 | 无 | `user` | 数据源的用户名。 | String | 是 | 无 | `password` | 用户的密码。 | String | 是 | 无 | `partitionColumn` | 用于并行读取数据的分区列。该列必须是数值类型。 | String | 否 | 无 | `lowerBound` | 分区列的下界值。 | Int | 否 | 无 | `upperBound` | 分区列的上界值。 | Int | 否 | 无 | `fetchSize` | 每次读请求中获取的行数。 | Int | 否 | `1000` | `readParallel` | 允许的并发读请求数。 | Int | 否 | `32` | `statement` | 用于从数据源检索数据的 SQL 语句。该配置项不能与`table`同时使用。 | String | 否 | 无 | `table` | 从中检索数据的表名。该配置项不能与`statement`同时使用。 | String | 否 | 无 | `custom_options` | 自定义 Spark JDBC 数据源选项,通常对应 Spark `DataFrameReader.option()`或`.options()`方法所设置的 JDBC 数据源选项。值为键值对映射,例如`custom_options:{isolationLevel:"NONE"}`。可用的键请参见 [Spark JDBC 数据源选项](https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html#data-source-option)。如果`custom_options`中的键与本页中的专用 JDBC 配置项(如`fetchSize`、`partitionColumn`等)重复,则`custom_options`中的值覆盖专用配置项的值。 | Map | 否 | 无 ## 通用源配置 下列配置项也可以作为全局设置在配置文件的`sourcesCommon`一节指定: - `type` - `url` - `driver` - `user` - `password` - `readParallel` 请注意,针对特定数据源的配置会覆盖全局设置。 ## 数据源配置示例 JDBC 源配置 ```` sources: [ { type:"jdbc" url:"jdbc:mysql://192.168.8.149:3306/movie" driver:"com.mysql.cj.jdbc.Driver" user:"nebula" password:"Nebula@123" partitionColumn: birthDate lowerBound:15 upperBound:60 fetchSize:1000 readParallel:20 #table:"actor" statement:"select people_id,name,birth_date from movie.actor" custom_options:{ isolationLevel:"NONE" } // nodetypes: [] // edgetypes: [] } ] ```` ## 完整配置示例 将``替换为登录账号的当前密码。若已修改密码,请使用修改后的密码。 ```` { taskType: import nebula: { graphAddr: "127.0.0.1:9669" graphName: "movie" user: "root" passwd: "" } error: { path: "/tmp/errors" maxRecords: 10000 } checkPoint: { path: "/tmp/checkpoint" resume: false } sourcesCommon:{ type:"jdbc" url:"jdbc:mysql://192.168.8.149:3306/movie" driver:"com.mysql.cj.jdbc.Driver" user:"nebula" password:"Yueshu@123" } writeCommon:{ batchSize: 2000 enableRealTimeQPSLog: true mode: "INSERT IGNORE" } sources: [ # node type Actor { statement:"select people_id,name,birth_date from movie.actor" pre_processes: { filter: ["birth_date!='\\N'"] concatConstant: [ { field: "name" prefixValue: "test_" suffixValue: "" } ] } nodetypes: [ { name: "Actor" sourceFields: [people_id,name,birth_date] nebulaFields: [id,name,birthDate] } ] } # node type Movie { statement:"select movie_id,name from movie.movie" nodetypes: [ { name: "Movie" sourceFields: [movie_id,name] nebulaFields: [id,name] } ] } # edge type Act { statement:"select people_id,movie_id from movie.act" edgetypes: [ { name: "Act" sourceKeys: [people_id] nebulaSrcKeys: [id] targetKeys: [movie_id] nebulaDstKeys: [id] sourceFields: [] nebulaFields: [] } ] } ] } ````