【发布时间】:2012-01-10 01:41:42
【问题描述】:
我正在尝试从 Java 连接到 MySQL 数据库(MySQL 托管在 WAMP 服务器中)
String userName = "root";
String password = "pass";
String url = "jdbc:mysql://localhost/dbase";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
当我从 localhost 运行时,连接很好。但是,当我从另一台计算机运行此代码时,将 localhost 替换为我计算机的 IP(在同一网络内),我收到错误,
message from server: "Host '<name>' is not allowed to connect to this MySQL server"
我也尝试过使用端口 3306。怎么了?
【问题讨论】:
-
查看此处 - forums.mysql.com/read.php?52,18966,134534 了解最可能的问题根源。
-
我相信mysql默认只有本地主机连接。您需要更改配置文件以允许本地主机之外的连接。因此,将您的 IP 地址添加到允许的用户。