简体   繁体   English

与Google Cloud SQL的连接间歇性断开

[英]Connection made to Google Cloud SQL drops intermittently

I am using a Google Cloud SQL using Java-SQL connector. 我正在使用使用Java-SQL连接器的Google Cloud SQL。 The issue I am facing is that the connection to database drops unexpectedly. 我面临的问题是与数据库的连接意外断开。 While Googling I came across this question and tried the solution suggested in the same question. 在谷歌搜索时,我遇到了这个问题,并尝试了同一问题中建议的解决方案。

In your console click the project, on the left side click Storage > CloudSQL then click on your database name . 在控制台中,单击项目,在左侧单击存储> CloudSQL,然后单击 数据库名称 You will see an 'Edit' button on top. 您会在顶部看到一个“编辑”按钮。 Click that and scroll down to Activation Policy , change it to Always On and then click save . 单击该按钮,然后向下滚动到“ 激活策略” ,将其更改为“ 始终在线” ,然后单击“ 保存”

But I'm still facing the same issue. 但是我仍然面临着同样的问题。 Fortunately I have been keeping the logs on Google App Engine and I have attached the snapshot of the exception that occurred while connecting to database. 幸运的是,我一直将日志保存在Google App Engine上,并附上了连接数据库时发生的异常快照。

Google App Engine Log For Cloud SQL连接下降

Gist of the code that I've posted below is used to establish connection to the database. 我在下面发布的代码要点用于建立与数据库的连接。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import com.google.appengine.api.utils.SystemProperty;
import static com.google.appengine.api.utils.SystemProperty.environment;
import static com.google.appengine.api.utils.SystemProperty.Environment.Value.Development;
import static com.google.appengine.api.utils.SystemProperty.Environment.Value.Production;

 Connection con=null;
SystemProperty.Environment.Value env = environment.value();
    if(env == Production)
    {
        System.out.println("Inside Production Phase");
        // Load the class that provides the new "jdbc:google:mysql://" prefix.
        Class.forName("com.mysql.jdbc.GoogleDriver");
        url = "jdbc:google:mysql://<my-project-id>:<cloud-sql-instance>/<database-name>?user=<user-name>&password=<database-password>&useUnicode=true&characterEncoding=UTF-8";
    }//if
    else if(env == Development)
    {
        System.out.println("Inside Development Phase");
        // This will load the MySQL driver, each DB has its own driver
        Class.forName("com.mysql.jdbc.Driver");
        url = "jdbc:mysql://127.0.0.1:3306/<database-name>?user=root";
    }//else if
    con = DriverManager.getConnection(url);

Is anyone facing the same problem, Please help. 有谁遇到同样的问题,请帮忙。

Got a temporary fix, used following parameters while making connection to Google Cloud SQL 连接到Google Cloud SQL时获得了临时修复,使用了以下参数

url = "jdbc:google:mysql://my-app:mysql2/project-name?user=root&password=password&autoReconnect=true&failOverReadOnly=false&maxReconnects=10";

Reference URL: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html 参考网址: https : //dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法与Google Cloud SQL建立连接 - Unable to create connection with Google Cloud SQL 生产中Google App Engine和Google Cloud SQL的连接出现问题 - Issue with connection from Google App Engine and Google Cloud SQL on production “无法创建与数据库服务器的连接” netbeans谷歌云sql错误 - “Could not create connection to database server” netbeans google cloud sql error 使用Java JDBC连接Google Cloud SQL数据库的方法 - Connection methods to Google Cloud SQL Database with Java JDBC Java Hibernate中的Google Cloud SQL数据库连接错误 - Google Cloud sql database connection error in java hibernate 是否可以将JPA连接池与Google App Engine和Cloud SQL一起使用? - Is it possible to use a JPA connection pool with Google App Engine and Cloud SQL? 来自localhost的谷歌云sql连接错误(Java eclipse) - Google cloud sql connection error from localhost (Java eclipse) Google Cloud Platform - Cloud SQL 上 MySQL 的 Spring Boot 应用程序连接问题 - Google Cloud Platform - Spring Boot application connection issues with MySQL on Cloud SQL Redshift连接偶尔会掉线 - Redshift connection occasionally drops Google Cloud Messaging - 服务器连接 - Google Cloud Messaging - server connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM