【发布时间】:2015-07-14 18:28:54
【问题描述】:
我在安装在 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
另外,我删除了 /etc/mysql/mysql.conf.d/mysqld.cnf 中的 bind_address 和 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
然后我想访问我本地机器上的数据库。
我在 Hibernate 中使用 Java。这是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)
因此,我想知道如何访问我的数据库。
【问题讨论】:
标签: mysql virtual-machine vmware