通过网络与JDBC连接到MySQL [英] Connect to MySQL with JDBC over network
问题描述
我正在尝试通过网络连接到MySQL数据库。我已安装MySQL,该服务正在默认端口上运行。我还将SQL连接器安装到jar文件,并将java JDK添加到服务器计算机。我可以使用以下代码连接到我的本地数据库:
I am trying to connect to MySQL database over a network. I have installed MySQL, and the service is running on the default port. I have also install the SQL connector to the jar file and added java JDK to the server machine. I am able to connect to my local database using the code:
private String dbUrl = "jdbc:mysql://localhost/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";
但是当我尝试通过网络连接到它时,使用IP地址(例如:192.168。 1.45):
But when I try and connect to it over the network, with the IP address (eg: 192.168.1.45):
private String dbUrl = "jdbc:mysql://192.168.1.45/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";
我收到连接错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
有谁知道这是什么问题?我需要添加不同的地址吗?
我已添加了地址的默认端口,但无法使其正常工作。
Does anyone know what this issue is? Do I need to add a different address? I have added the default port with the address but cannot get it to work.
感谢您的帮助。
推荐答案
- 检查my.cnf [mysqld]设置参数port bind-address ,socket,to确保这些不会导致问题。
- 检查文件/ etc / hosts,/ etc / hosts.deny以确保一切正常。
- 检查防火墙应用程序
- 检查以确保mysqld的任何目录都具有适当的权限。
- 检查以确保mysql数据库(用户表)中的安全设置允许从远程主机进行访问。
- 确保您可以telnet OK到localhost 3306,127.0.0.1 3306,以及您的计算机配置的任何其他IP地址(使用ifconfig查找)。
- Check the my.cnf [mysqld] settings for the parameters port, bind-address, socket, to make sure these aren't causing problems.
- Check the files /etc/hosts, /etc/hosts.deny to make sure everything is ok.
- Check firewall applications
- Check to make sure whatever directory mysqld's sockets are have the appropriate permissions.
- Check to make sure that security settings within the mysql database (user table) permit access from your remote host.
- Make sure you can telnet OK to localhost 3306, 127.0.0.1 3306, and whatever other IP address your machine is configured to (use ifconfig to find out).
这篇关于通过网络与JDBC连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!