我有 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 配置文件)