我有一个谷歌云平台 - 计算引擎实例,我安装了MySQL服务器。
现在我无法获得安装sql的虚拟机生命信号, 例如:
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();
}
}
它需要几秒钟,就像他试图连接和EXEPTION
一样in conncection
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
我做了什么让它发挥作用:
bind address = 0.0.0.0
,skip-external-locking comment out
我不知道该怎么做。
答案 0 :(得分:0)
您必须对my.cnf
文件进行以下更改
my.cnf
bind-address = www.000webhost.com (OR)
bind-address = xx.xx.xx.xx (IP Address)
更改此设置后,您需要重新启动MySQL服务。
另外值得注意的是MAMP / MAMP Pro默认设置MAMP_skip-networking_MAMP
。您必须在my.cnf
如果您没有任何用户登录问题,您应该能够从Java代码连接到MySQL数据库。
答案 1 :(得分:0)
在我的情况下,根本原因是:防火墙。我试图在工作中运行该应用程序。
有趣的是,本地运行的App Engine Standard实际上在Google Cloud Platform Logs中生成了一个非错误日志,这让我放弃了防火墙假设。
解决方案:我发现把笔记本从家里拿来并连接到公司的网络,都没用。当我连接到移动设备中的共享连接时,工作得很好。