简体   繁体   中英

Connection mySQL and hibernate problems

I want to connect a project in Java with hibernate and mySQL databases. I rent a server to Ovh (kimsufi configure on ubuntu server and i configure mysql);

I can connect to phpmyadmin from distant computer 39. . .*/phpmyadmin , create databases tables ect...

But with hibernate I can't and I don't know why.

When i launch the application it raise an error :

WARN: SQL Error: 1130, SQLState: HY000 3 déc. 2013 13:09:45 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: null, message from server: "Host 'ALyon-654-1-427-15.w109-212.abo.wanadoo.fr' is not allowed to connect to this MySQL server" Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not open connection

Here is my hibernate cfg file :

<!-- <?xml version="1.0" encoding="UTF-8"?> -->
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >

<hibernate-configuration>  
<session-factory>  
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>  
    <property name="hibernate.connection.username">athos</property>  
    <property name="hibernate.connection.password">*******</property>  
    <property name="hibernate.connection.url">jdbc:mysql://37.*.*.*:3306</property>  
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>  
    <property name="show_sql">true</property>   
    <property name="connection.pool_size">1</property>  

    <mapping class="fr.javatp.model.Client"></mapping>  

</session-factory>  
</hibernate-configuration>  

The computer you're using to connect to the kimsufi server isn't allowed to connect as user athos to the mysql database. A detailed writeup can be found here . Essentially, you grant the appropriate rights with a GRANT command:

GRANT ALL ON yourdb.* TO athos@'1.2.3.4' IDENTIFIED BY 'my_password';

But that won't work with dynamic residential connections of course.

Alternatively, you could forward the traffic through an ssh tunnel between your machine and the kimsufi server, or even set up an OpenVPN server on the kimsufi server.

In my opinion, both these options are security-wise a LOT better than eg setting up phpMyAdmin.

Last but not least, add the database name to the JDBC URL:

jdbc:mysql://37.*.*.*:3306/yourdbnameshouldgohere

The error message is pretty clear

"Host 'ALyon-654-1-427-15.w109-212.abo.wanadoo.fr' is not allowed to connect to this MySQL server".

It means that your host is not allowed to connect to the remote SQL database. You need to allow your host to do remote connection via phpMyadmin (if it is possible with OVH. I'n not sure about that!)

http://supportcenter.verio.com/KB/questions.php?questionid=494

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM