Alex Rivera | Logout

Cannot connect to MySQL - host not allowed

Asked 2012-11-14T12:09:25.520
11

I've just started working with Hibernate and when I'm finally trying to launch the web-app I get the following error:

2012-nov-14 12:54:23 org.hibernate.tool.hbm2ddl.SchemaExport execute
ERROR: HHH000231: Schema export unsuccessful
java.sql.SQLException: null,  message from server: "Host '192.168.1.7' is not allowed to
connect to this MySQL server"

Which is really frustrating. Why aren't I a localhost? What is 192.168.1.7? I could just grant privileges like the answers to similar questions suggest but why aren't I localhost?

I understand the problem here, the hbm2ddl setting is set to create, so it wants to create the given tables but doesn't get permission from the MySQL-server.

I'm developing a struts2/hibernate app in Eclipse and I use Tomcat and of course MYSQL.

Thanks in advance!

EDIT: (hibernate.cfg.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="connection.driver_class"> com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/clothes</property>
    <property name="connection.username">root</property>
    <property name="connection.password">root</property>

    <property name="connection.pool_size">1</property>
    <property name="dialect"> org.hibernate.dialect.MySQLDialect</property>

    <property name="show_sql">true</property>

    <!-- Needs to be disabled in production! -->
    <property name="hbm2ddl.auto">create</property>

    <mapping class="johanstenberg.clothes.serverobjects.AdEntity"/>
    <mapping class="johanstenberg.clothes.serverobjects.AuthenticationEntity"/>
    <mapp
Edit
Report

1 Answer

13

Look into your hibernate configuration file. There is an entry with

<property name="connection.url"> ... </property>

You must change this entry to connect to mysql at localhost.

Next look into mysql. Connect to mysql and check privileges:

$ mysql -u root -p
mysql> show grants for 'root'@'localhost';
mysql> show grants for 'root'@'192.168.1.7';

If there are no grants for the appropriate database or tables, add them:

mysql> grant all privileges on clothes.* to 'root'@'localhost' identified by 'password';

or

mysql> grant all privileges on clothes.* to 'root'@'192.168.1.7' identified by 'password';

and then

mysql> flush privileges;

answered 2012-11-14T12:17:39.290

Your Answer