0

Facing exception "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception." when trying to connect with mysql instance in google cloud data fusion.

  • created cloud data fusion instance
  • From Wrangler-->Add connection --> Added the jar build(created from pom.xml given below) as a driver
  • In Add connection used the connection string as "dbc:mysql://google/mysql?cloudSqlInstance=socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false"
  • While Testing the connection, it throws error, "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception."

This is my pom.xml and I build the fat jar using mvn package.

<?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>
NitinM
  • 303
  • 4
  • 12
  • 1
    Edit your question and include 1) the source code (not a link to someplace else). 2) The error (stack trace) that you are getting. 3) Read this document to help you with your question: https://stackoverflow.com/help/how-to-ask – John Hanley Sep 20 '19 at 19:48
  • You have to isolate this issue further. Check if its a jar issue or permissions issue. Share the error and we would be able to help you further. – Kunal Deo Sep 21 '19 at 16:50
  • @kunal - It shows only this error on screen "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception." Nothing more shown on the screen. So I can not find what is the actual reason for the exception. – NitinM Sep 21 '19 at 18:14

1 Answers1

0

Use MySQL instead:

  1. From the Add Connection> Database Search for MySQL
  2. Download the MySQL Driver from dev.mysql.com. Unzip.
  3. On the hub again this time click Deploy Upload mysql-connector-java-5.x.xx-bin.jar
  4. Go back to Add Connection> Database, you should see green tick against MySQL driver
  5. Click on MySQL driver and setup the connection parameter.

Make sure you have added the relevant network in the Cloud SQL screen to allow Datafusion instance to make connection to Cloud SQL. If Datafusion is running in the same project then you dont need to do anything else.

Kunal Deo
  • 2,248
  • 2
  • 18
  • 27
  • 1
    How to get/assign IP of/for data fusion instance? – NitinM Sep 25 '19 at 08:17
  • If they are running in the same project then you dont need to do anything else. – Kunal Deo Sep 25 '19 at 08:46
  • we are running same project, trying to connect from datafusion to cloud sql mysql and got "Not authorized to access resource." in sql instance errorlog. so rights are issue. (it's strange somehow, because fusion can see some services from same project - bigquery, storage and few more) – Alexo Po. Nov 24 '21 at 12:48