简体   繁体   English

连接MySQL和休眠问题

[英]Connection mySQL and hibernate problems

I want to connect a project in Java with hibernate and mySQL databases. 我想用休眠和MySQL数据库连接Java中的项目。 I rent a server to Ovh (kimsufi configure on ubuntu server and i configure mysql); 我将服务器租给Ovh(在ubuntu服务器上配置kimsufi,并配置mysql);

I can connect to phpmyadmin from distant computer 39. . 我可以从远程计算机39连接到phpmyadmin .*/phpmyadmin , create databases tables ect... 。* / phpmyadmin,创建数据库表等...

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. 警告:SQL错误:1130,SQLState:HY000 3dé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 2013 13:09:45 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions错误:null,来自服务器的消息:“主机'ALyon-654-1-427-15.w109-212.abo.wanadoo.fr'是不允许连接到此MySQL服务器”线程“主”中的异常org.hibernate.exception.GenericJDBCException:无法打开连接

Here is my hibernate cfg file : 这是我的休眠cfg文件:

<!-- <?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. 您用来连接到kimsufi服务器的计算机不允许以用户身份连接到mysql数据库。 A detailed writeup can be found here . 详细的文章可以在这里找到。 Essentially, you grant the appropriate rights with a GRANT command: 本质上,您可以使用GRANT命令授予适当的权限:

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. 或者,您可以通过计算机和kimsufi服务器之间的ssh隧道转发流量,甚至可以在kimsufi服务器上设置OpenVPN服务器。

In my opinion, both these options are security-wise a LOT better than eg setting up phpMyAdmin. 在我看来,这两个选项在安全性上要比设置phpMyAdmin好得多。

Last but not least, add the database name to the JDBC URL: 最后但并非最不重要的一点是,将数据库名称添加到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". “不允许主机'ALyon-654-1-427-15.w109-212.abo.wanadoo.fr'连接到该MySQL服务器”。

It means that your host is not allowed to connect to the remote SQL database. 这意味着您的主机不允许连接到远程SQL数据库。 You need to allow your host to do remote connection via phpMyadmin (if it is possible with OVH. I'n not sure about that!) 您需要允许主机通过phpMyadmin进行远程连接(如果使用OVH是可行的。我不确定!)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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