Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://db.153.com/test","root","bcmedia"); 异常发生在这一句,返回异常: java.sql.SQLException: null, message from server: "#HY000Host '172.16.16.55' is not allowed to connect to this mysql server"'172.16.16.55' 是我本机IP. 什么原因?
原因是你的帐号不允许从远程登陆,只能在localhost中登录。此时只要在 localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"(unix为例)
mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
说明你的本机没有权限连接到db.153.com/testdb.153.com这是一个什么地址? 请问LZ得到授权了么?
这肯定是数据库访问权限的问题。
是不是在装MySql 的时候,没有设置MySql 的服务端哦,导致无法连接。
你先用localhost 试试看,再用排除法一步步慢慢的调试,问题总会解决的。
XXXX的地方填写你root的密码
% test test 用这个user登陆也出同一exception