簡體   English   中英

使用PC客戶端的Java應用連接到mysql

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

我已經將mysql安裝到Windows PC(IP 192.168.1.100),並且已經制作了Java應用程序

當將應用程序與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);

我無法從同一網絡中的其他PC運行它。 我使用的代碼是

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);

我應該使MySQL Workbench停止與pther pc的連接嗎?

您必須授予IP地址的權限。

在命令行(cmd.exe)上執行:

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

Windows防火牆可能會阻止端口3306。

如果您不希望從遠程PC獲得完整的root權限,則也許應該首先創建一個用戶emiuser

然后,您可以在本地測試192.168.1.100:3306。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM