【问题标题】:Translating PHPMyAdmin MySQL connection configuration to JDBC将 PHPMyAdmin MySQL 连接配置转换为 JDBC
【发布时间】:2011-07-20 15:48:52
【问题描述】:

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

【问题讨论】:

    标签: java php mysql jdbc blowfish


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!我认为授权是可以的:运行 PHPMyAdmin 的机器也在运行 java,PHPMyAdmin 连接到 MySQL 没有问题。你认为 PHPMyAdmin 是否一直保持与该用户的连接,当我没有登录时?
    • PHP 应用程序不像 java,每次请求都会建立连接。如果您使用相同的用户/密码组合在同一台机器上连接,那么它应该可以工作。您可能想在这里查看 phpMyAdmin 的配置选项的含义:phpmyadmin.net/documentation/Documentation.html#setup
    • 好的。所以问题似乎出在其他地方。可能是一些糟糕的 jdbc 驱动程序、java 端的连接问题或 MySQL 中的一些配置。无论如何,我认为导出数据库并将其安装在前端服务器上就可以了。感谢您的帮助!
    猜你喜欢
    • 2016-04-10
    • 2011-10-30
    • 2012-02-16
    • 2010-09-20
    • 2018-05-30
    • 2016-03-02
    • 2020-12-24
    • 2011-05-07
    相关资源
    最近更新 更多