将PHPMyAdmin MySQL连接配置转换为JDBC

时间:2011-07-20 15:48:53

标签: java php mysql jdbc blowfish

我让PHPMyAdmin使用这些参数连接到远程MySQL服务器:

$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”=“cookie”在Java中没有被考虑。

我该如何解决这个问题?

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

1 个答案:

答案 0 :(得分:1)

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

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