[問題] 透過SSH連線至Mysql拿資料
大家好,
目前我想要連線至SSH然後再連到Mysql得到database資料,
可是到
conn = DriverManager.getConnection (url, dbuserName, dbpassword);
這行就會發生exception
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 3306): connect failed: ECONNREFUSED (Connection refused)
試了很多方法結果都還是一樣,
目前是在Android Studio上用Java撰寫Android的App
請問有人發生過類似的情形嗎?
下面我簡化之後的code
http://codepad.org/kwwZv05Z
謝謝大家。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.169.189.152
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1428939717.A.F48.html
※ 編輯: rex5207 (1.169.189.152), 04/13/2015 23:43:18
推
04/14 00:38, , 1F
04/14 00:38, 1F
→
04/14 00:38, , 2F
04/14 00:38, 2F
你好,這部分我也嘗試過,我把localhost換成真實的ip位置後,會有另一個exception
java.sql.SQLException:
Access denied for user 'root'@'180-177-106-21.dynamic.kbronet.com.tw'
(using password: YES)
※ 編輯: rex5207 (180.177.106.21), 04/14/2015 00:57:03
推
04/14 01:06, , 3F
04/14 01:06, 3F
剛剛看了一下,3306的port有打開,
我用sql workbench連SSH到Mysql也可以正確拿到database裡面的資料,
http://shaocian.blogspot.tw/2012/11/mysql.html
然後我剛剛看到了這篇,是不是要開放權限給root?
不過我用workbench連Mysql可以拿到資料.....
謝謝
※ 編輯: rex5207 (180.177.106.21), 04/14/2015 01:41:04
→
04/15 08:32, , 4F
04/15 08:32, 4F
→
04/15 17:56, , 5F
04/15 17:56, 5F
推
04/15 21:54, , 6F
04/15 21:54, 6F
推
04/16 13:32, , 7F
04/16 13:32, 7F
→
04/16 15:55, , 8F
04/16 15:55, 8F
→
04/16 15:55, , 9F
04/16 15:55, 9F