简体   繁体   English

使用PC客户端的Java应用连接到mysql

[英]Connect to mysql with java app of pc client

i have install mysql to a windows pc (with ip 192.168.1.100) and i have made a java application 我已经将mysql安装到Windows PC(IP 192.168.1.100),并且已经制作了Java应用程序

when a run the application to the same pc with mysql it's runing 当将应用程序与mysql运行到同一台PC上时

String userName = "root";
String password = "1234";
String url = "jdbc:mysql://localhost/emi";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);

i can't run it from other pc in the same network. 我无法从同一网络中的其他PC运行它。 the code i use is 我使用的代码是

String userName = "root";
String password = "1234";
String url = "jdbc:mysql://192.168.1.100:3306/emi";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);

Should I make MySQL Workbench to alow connection from pther pc? 我应该使MySQL Workbench停止与pther pc的连接吗?

You have to grant rights to the IP address. 您必须授予IP地址的权限。

Execute on the command line (cmd.exe): 在命令行(cmd.exe)上执行:

C:\....> mysql -uroot -p 1234
mysql> GRANT ALL ON emi.* TO root@'192.168.1.100' IDENTIFIED BY '1234';
mysql> \q

And the Windows firewall might block port 3306. Windows防火墙可能会阻止端口3306。

Maybe you should first create a user emiuser , if you do not want full root rights from a remote PC. 如果您不希望从远程PC获得完整的root权限,则也许应该首先创建一个用户emiuser

You can then locally test 192.168.1.100:3306. 然后,您可以在本地测试192.168.1.100:3306。

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

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