简体   繁体   中英

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

when a run the application to the same pc with mysql it's runing

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. 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?

You have to grant rights to the IP address.

Execute on the command line (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.

Maybe you should first create a user emiuser , if you do not want full root rights from a remote PC.

You can then locally test 192.168.1.100:3306.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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