[英]Unable to connect Cloud SQL mySql / postgreSQL instance from Data Fusion
Goal is to connect Cloud SQL mysql or postgreSQL instances using Cloud Data Fusion.目标是使用 Cloud Data Fusion 连接 Cloud SQL mysql 或 postgreSQL 实例。
While testing connection, it fails with error: com.mysql.jdbc.Driver在测试连接时,它失败并显示错误:com.mysql.jdbc.Driver
Expecting testing of the connection with Cloud SQL MySQL to be successful so that the data fusion pipeline can be built.期待与 Cloud SQL MySQL 的连接测试成功,以便构建数据融合管道。
The issue is that you need to provide a jar that has both the driver and the connector included.问题是您需要提供一个包含驱动程序和连接器的 jar。 You can find instructions on how to build a uberjar (also called a farjar) using the driver and JDBC Socket Factory from this post here .您可以在此处的这篇文章中找到有关如何使用驱动程序和 JDBC Socket Factory 构建 uberjar(也称为 farjar)的说明。
Edit: Here is a POM for MySQL:编辑:这是 MySQL 的 POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mysql-with-cloud-sql-socket-factory</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-8</artifactId>
<version>1.0.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
It is a bit annoying to see "error: com.mysql.jdbc.Driver not found" and nothing more that can point to the root cause.看到“error: com.mysql.jdbc.Driver not found”有点烦人,没有更多可以指出根本原因的内容。 Nevertheless, the error message in Data Fusion it is correct because the mysql Driver class is not included when the package is manually built .尽管如此,Data Fusion 中的错误消息是正确的,因为手动构建包时不包含 mysql Driver 类。 The issue is coming from this line:问题来自这一行:
<scope>provided</scope>
in the cloud-sql-jdbc-socket-factory/connector-j-8/pom.xml file which means that the target package won't include the mysql-connector-java
jar file, the one that contains com.mysql.jdbc.Driver
and others.在cloud-sql-jdbc-socket-factory/connector-j-8/pom.xml文件中,这意味着目标包将不包含mysql-connector-java
jar 文件,该文件包含com.mysql.jdbc.Driver
等。 The error can be resolved if you construct the jar connector without the aforementioned line.如果您在没有上述行的情况下构建 jar 连接器,则可以解决该错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.