Cannot connect to MySQL - host not allowed

I just started working with Hibernate, and when I finally try to start a web application, 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" 

What really upsets. Why am I not a local host? What is 192.168.1.7? I could just provide privileges, for example, answers to such questions, but why am I not localhost?

I understand the problem here, the hbm2ddl parameter is configured to create, so it wants to create the table data, but does not get permission from the MySQL server.

I am developing a struts2 / hibernate application in Eclipse and I am using 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"/> <mapping class="johanstenberg.clothes.serverobjects.UserEntity"/> <mapping class="johanstenberg.clothes.serverobjects.VerificationKeyEntity"/> </session-factory> </hibernate-configuration> 
+7
source share
3 answers

Look at your hibernation configuration file. There is a record with

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

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

Next, view mysql. Connect to mysql and check permissions:

$ 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 corresponding database or tables, add them:

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

or

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

and then

mysql> privileges flush;

+10
source

run this command on your MySQL instance (replace tokens)

 CREATE USER '${username}'@'%' IDENTIFIED BY '${password}'; GRANT ALL ON *.* TO '${username}'@'%'; 

this will allow you to connect to mysql from any host. 192.168.1.7 is the ip of your computer.

If you want to protect your db instance, read this bit of mysql documentation .

+6
source

There are several steps you need to follow:

Step1: do some configuration on my.conf

 sudo vi /etc/mysql/my.cnf bind-address = 0.0.0.0 

Step 2: go to mysql command (("your_remote_ip" is the computer that wants to access your mysql))

 mysql -u root -p GRANT ALL PRIVILEGES ON *.* TO 'your_mysql_username'@'your_remote_ip'IDENTIFIED BY 'your_mysql_password' WITH GRANT OPTION; 

Step 3: you can check its configuration in mysql

 use mysql; select user, host from user; 

Step 4: restart mysql

 sudo /etc/init.d/mysql restart 
0
source

All Articles