先介绍一下我的软件环境
Eclipse 3.1
Hiberate 3.0
Mysql 4.0.12
winxp sp2
我的数据库服务和web服务都在一台机器上,ip为192.168.10.74,mysql 用户名为root ,host为localhost
当在connection.url中设定值为jdbc:mysql://192.168.0.74:3306/news 时,有以下异常
java.sql.SQLException: null, message from server: "Host '192.168.0.74' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:991)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at com.hexin.site.db.hibernate.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:68)
我就纳闷了,192.168.0.74不就是你自己的地址吗?为什么不允许访问。后来抱着侥幸的心理把192.168.0.74改称了127.0.0.1。嘿嘿,居然可以了。看来mysql显得不怎么聪明哦。
--转自