If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Remote connection to MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-07-09, 05:05
DavidFab DavidFab is offline
Registered User
 
Join Date: Jun 2009
Posts: 1
Remote connection to MySQL

I have created a MySQL (5.0.77-community) database at a non-free webhosting service. In cPanel I created a new user with all possible privileges and added '%' as an access host. I would like to connect to this base remotely (as in not from the phpMyAdmin in cPanel). More precisely I would like to connect to this database with JDBC, but help on connecting with any remote client would be much appreciated. I did try googling for a solution but I found nothing of use.

This is the code I use for connecting:
Java Syntax (Toggle Plain Text)

1.
new org.gjt.mm.mysql.Driver();
2.
Connection c = DriverManager.getConnection("jdbc:mysql://"+server_ip+":3306/"+database_name, username, password);

new org.gjt.mm.mysql.Driver(); Connection c = DriverManager.getConnection("jdbc:mysql://"+server_ip+":3306/"+database_name, username, password);

And this is the exception I get:
Quote:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ption: Communications link failure

Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
at com.mysql.jdbc.SQLError.createCommunicationsExcept ion(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connect ion.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager .java:582)
at java.sql.DriverManager.getConnection(DriverManager .java:185)
at BaseObjects.NewMain.main(NewMain.java:25)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2026)
... 12 more
Java Result: 1

BTW: Accessing to a local server this way gives no errors (but unfortunately this is not an option for the final version of my project). Oh and the error is thrown by the getConnection method.
Reply With Quote
  #2 (permalink)  
Old 06-09-09, 22:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,451
Don't you think your "non-free webhosting service" may be blocking port 3306? You could try running MySQL on a port that is not likely to be blocked, like 21 or 25.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On