2011-07-20 63 views
1

我有phpMyAdmin连接到远程MySQL服务器,使用这些参数:翻译的phpMyAdmin MySQL连接配置JDBC

$cfg['blowfish_secret'] = 'ba17c1ec07d65003'; 
/* Authentication type */ 
$cfg['Servers'][$i]['auth_type'] = 'cookie'; 
/* Server parameters */ 
$cfg['Servers'][$i]['host'] = '*remoteServer*:3306'; 
$cfg['Servers'][$i]['extension'] = 'mysql'; 
$cfg['Servers'][$i]['controluser'] = '*user*'; 
$cfg['Servers'][$i]['controlpass'] = '*password*'; 

我试图连接到Java的这个MySQL服务器,无论这些工作:

final String url ="jdbc:mysql://*remoteServer*:3306/*user*"; 
Connection conn = DriverManager.getConnection(url, "*user*", "*password*"); 

,并与 “3306” 中删除:

final String url ="jdbc:mysql://*remoteServer*/*user*"; 
Connection conn = DriverManager.getConnection(url, "*user*", "*password*"); 

我得到这个错误:

SQLException: 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. 
SQLState:  08S01 
VendorError: 0 
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. 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    ... 

我认为它来自“blowfish_secret”(这仅仅是一个随机Cookie)和“AUTH_TYPE” =“曲奇”不被占的Java。

我该如何解决这个问题?

另外,我是否需要告诉MySQL他必须接受与jdbc驱动程序交谈? (如果是的话,我搞砸了,我没有访问MySQL配置文件)

回答

1

blowfish_secret和auth_type只用作phpmyadmin软件的一部分,它们与mysql连接无关。

您是否有防火墙允许从运行java的机器访问MySQL,并且您是否设置了从该特定主机访问该用户的授权?

+0

谢谢! 我认为这些授权是可以的:运行PHPMyAdmin的机器也运行java,并且PHPMyAdmin没有连接到MySQL的问题。您是否认为PHPMyAdmin始终与该用户保持连接,当我没有登录时发生事件? – BenoitParis

+0

PHP应用程序不像java,连接建立在每个请求上。如果你使用相同的用户/密码组合连接在同一台机器上,那么它应该可以工作。你可能想看看phpMyAdmin的配置选项在这里意味着什么:http://www.phpmyadmin.net/documentation/Documentation.html#setup – datasage

+0

好的。所以这个问题似乎在别处。也许一些坏的jdbc驱动程序,java端的连接问题,或者MySQL中的一些配置。无论如何,我认为导出数据库并将其安装在前台服务器上会很好。感谢您的帮助! – BenoitParis