无法连接到谷歌实例中托管的MYSQL服务器

问题描述 投票:0回答:2

我有一个谷歌云平台 - 计算引擎实例,我安装了MySQL服务器。

现在我无法获得安装sql的VM生命信号,例如:

package com.company;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {

public static void connection(){
    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("in conncection");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

public static void connectToMySQL(){
    connection();
    String host = "jdbc:mysql://hotsIP:3306/DBname";
    String user = "user";
    String pass = "password";
    try {
        Connection connection = DriverManager.getConnection(host,user,pass);
        System.out.println("???");
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    connectToMySQL();
}
}

这需要几秒钟,就像他试图连接和EXCEPTION一样

in conncection
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

我做了什么让它工作:

  • 在my.cnf:qazxsw poi,qazxsw poi
  • 重启服务器
  • 查看服务器是否处于活动状态
  • 看看服务器是否在监听端口
  • 看看它的TCP

我不知道该怎么办了。

java mysql jdbc google-cloud-platform google-compute-engine
2个回答
0
投票

您必须对bind address = 0.0.0.0文件进行以下更改

skip-external-locking comment out

my.cnf

更改此设置后,您需要重新启动MySQL服务。

另外值得注意的是,MAMP / MAMP Pro默认设置my.cnf。你必须在你的bind-address = www.000webhost.com (OR) bind-address = xx.xx.xx.xx (IP Address) 中禁用这一行

如果您没有任何用户登录问题,您应该能够从Java代码连接到MySQL数据库。


0
投票

在我的情况下,根本原因是:防火墙。我试图在工作中运行该应用程序。

有趣的是,本地运行的App Engine Standard实际上在MAMP_skip-networking_MAMP中生成了一个非错误日志,这让我放弃了防火墙假设。

解决方案:我发现将笔记本电脑从家里带到公司的网络连接,没有用。当我连接到我的手机中的共享连接时,工作得很好。

© www.soinside.com 2019 - 2024. All rights reserved.