【发布时间】:2013-12-02 15:47:18
【问题描述】:
我有一个谷歌应用引擎连接项目,我正在尝试连接到谷歌云 sql 数据库。我将项目上传到谷歌并通过它尝试连接到数据库。
我的连接网址如下->
Class.forName("com.mysql.jdbc.GoogleDriver");
String password="";
url = "jdbc:google:mysql://my-project-id:my-instance-name/dbname?user=root&password="+password+"useUnicode=true&characterEncoding=UTF-8";
Connection conn = DriverManager.getConnection(url);
在我尝试与我得到异常的 url 建立连接时
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
然后我将以下字符串添加到我的 url-> &autoReconnect=true&failOverReadOnly=false&maxReconnects=10
然后收到不同的异常-->
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 10 times. Giving up.
我已经尝试ping通数据库实例的IP地址,它工作正常。
我是否需要在我的云 sql 实例中授予任何显式权限才能使其能够连接?
欢迎提出任何建议。
奇怪的是,我可以通过项目->google->app engine->usegoogle cloud sql instance->configure使用eclipse连接到数据库。我使用相同的用户名(root)和密码("") 此处与代码中的 url 一样,但由于某种原因,它拒绝通过代码进行连接。 我也启用了
<use-google-connector-j>true</use-google-connector-j>
我的标签 appengine-web.xml
我将 root 密码从 "" 更改为某个值,并且可以通过 mysql 客户端进行连接 我可以访问数据库,但是在代码中提供相同的密码时它拒绝连接。
任何建议将不胜感激。 谢谢, 劳拉
【问题讨论】:
-
数据库服务是否正在运行?
-
我查看了云 sql 下的摘要选项卡(单击我的实例 ID),它说状态正在运行。
-
在授权 IP 地址下:我有“无”,是否需要提及任何 IP 地址才能连接?这可能是个问题吗?
-
如果您使用实例 IP 连接,这是从本地计算机连接的推荐方式,是的,您应该将您的 IP 地址列入白名单以允许传入连接。如果您从 App Engine 连接(不是从本地开发服务器,而是从 Google 生产服务器),那么您需要授权 AppEngine 应用程序。
标签: java mysql google-app-engine jdbc google-cloud-sql