我在安装在VMware中的xubuntu 15.04中安装了MySQL 这是MySQL的细节:
mysql Ver 14.14 Distrib 5.6.24, for debian-linux-gnu (i686) using EditLine wrapper
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
我已设置netstat。
@ubuntu:~$ netstat -an|grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
另外,我删除了 bind_address & /etc/mysql/mysql.conf.d/mysqld.cnf 中的 skip-externak-locking (我在 / etc / mysql / my中找不到这两个.cnf 。我只在mysqld.cnf中找到它们。)并重启mysql。
我还设置了MySQL的用户:
mysql> create user 'test'@'localhost' identified by 'MY_PASSWORD';
mysql> create user 'test'@'%' identified by 'MY_PASSWORD';
mysql> grant all on *.* to 'test'@'localhost';
mysql> grant all on *.* to 'test'@'%';
正如https://stackoverflow.com/a/21382716/1618596所说,我打开了mysql的端口:
sudo /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
然后我想在本地机器上访问数据库 我在Java中使用Hibernate。这是hibernate.cfg.xml的代码(192.168.96.130是我的xubuntu的ip地址)
<?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 name="">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.96.130/Test_DB</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">MY_PASSWORD</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
但它显示错误:
WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.engine.jndi.JndiException: Error parsing JNDI name []
at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:141)
at org.hibernate.engine.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:157)
at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:103)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:497)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at M.main(M.java:14)
因此,我想知道如何访问我的数据库。
答案 0 :(得分:-1)
这是因为hibernate生成工具与最新版本的hibernate不同。截至今天,您将在Hibernate Core 4.3.10 Final和JBoss Tools 4.2.3最终版本(考虑最新版本)中出现此错误。