0

面临异常“由于基础异常,无法创建套接字工厂'com.google.cloud.sql.mysql.SocketFactory'。” 尝试在谷歌云数据融合中连接 mysql 实例时。

  • 创建云数据融合实例
  • 从牧马人->添加连接->添加 jar 构建(从下面给出的 pom.xml 创建)作为驱动程序
  • 在添加连接中,使用连接字符串为“dbc:mysql://google/mysql?cloudSqlInstance=socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false”
  • 在测试连接时,它会抛出错误,“由于底层异常,无法创建套接字工厂'com.google.cloud.sql.mysql.SocketFactory'。”

这是我的 pom.xml,我使用 mvn 包构建了 fat jar。

<?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.13</version>
        </dependency>

        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>mysql-socket-factory-connector-j-8</artifactId>
            <version>1.0.15</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>

    <profiles>
        <profile>
            <id>jar-with-dependencies</id>
            <properties>
                <lane>jar-with-dependencies</lane>
            </properties>
        </profile>
    </profiles>
</project>
4

1 回答 1

0

改用 MySQL:

  1. 从添加连接>数据库搜索 MySQL
  2. 从dev.mysql.com下载 MySQL 驱动程序。解压缩。
  3. 这次再次在集线器上单击 Deploy Upload mysql-connector-java-5.x.xx-bin.jar
  4. 返回添加连接> 数据库,您应该会看到 MySQL 驱动程序的绿色勾号
  5. 单击 MySQL 驱动程序并设置连接参数。

确保您已在 Cloud SQL 屏幕中添加相关网络,以允许 Datafusion 实例连接到 Cloud SQL。如果 Datafusion 在同一个项目中运行,那么您不需要做任何其他事情。

于 2019-09-21T19:28:43.730 回答