Java 通过局域网访问 Mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24133933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql access over LAN
提问by sky3287944
I have created a java application which connects to a mysql database using the JDBC driver. I have the mysql server running on the same machine as my java application.
我创建了一个 java 应用程序,它使用JDBC 驱动程序连接到 mysql 数据库。我的 mysql 服务器与我的 java 应用程序在同一台机器上运行。
When I connect to the database on localhost the application is working fine. My system in connected to other systems via LAN. Now i want to run my application on these systems connecting to the database on the mysql server i have on my system.
当我连接到本地主机上的数据库时,应用程序工作正常。我的系统通过局域网连接到其他系统。现在我想在这些系统上运行我的应用程序,这些系统连接到我系统上的 mysql 服务器上的数据库。
What changes do i need to make in my mysql workbenchor the java applicationto deploy this. I have mysql 6.1 workbench installed.
我需要在我的mysql 工作台或java 应用程序中进行哪些更改来部署它。我安装了 mysql 6.1 工作台。
I am getting the following error:
我收到以下错误:
run: Communications link failure
Last packet sent to the server was 0 ms ago. Exception in thread
"AWT-EventQueue-0" java.lang.NullPointerException
at help.helpdesk.Ready(helpdesk.java:97)
at help.helpdesk.<init>(helpdesk.java:89)
at help.helpdesk.run(helpdesk.java:428)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) BUILD
SUCCESSFUL (total time: 22 seconds)
when I try to connect to the database on my local server by using the ip address of my system.
当我尝试使用系统的 IP 地址连接到本地服务器上的数据库时。
回答by Gabber
You need to do following changes
您需要进行以下更改
1.Edit the my.cnf
1.编辑my.cnf
mysql/my.cnf
change the local ip
更改本地ip
bind-address = 192.168.1.2("your system ip")
2.restart the mysql server
2.重启mysql服务器
and if you want connect to your database remotely than this linkwill helpful for you
如果您想远程连接到您的数据库,那么此链接将对您有所帮助
回答by Matt
If you set bind-address = 0.0.0.0 in /etc/my.cnf, MySQL will be available across all interfaces both locally and over the network.
如果在 /etc/my.cnf 中设置 bind-address = 0.0.0.0,MySQL 将在本地和网络上的所有接口上可用。
回答by Vivek Dwivedi
for windows goto: C:/Program Files/MySQL/MySQL Server 6.1/ and edit the file "my-default"
对于 Windows 转到:C:/Program Files/MySQL/MySQL Server 6.1/ 并编辑文件“my-default”