Remote access to mySQL database

Nicko

Expert Member
Joined
Feb 16, 2010
Messages
1,048
Reaction score
1
Location
Cape Town
Im trying to connect to my mySQL database hosted on elitehost.co.za.

I'm new at this so I do apologise in advance if this is obvious or I don't provide all the information needed (I swap same names with example names).

URL: pcassemble.co.za
Database: X
User: jim
Password: pwd

try{
String url = "jdbc:mysql://pcassemble.co.za:3306/X";
Class.forName ("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection (url,"jim","pwd");
System.out.println ("Database connection established");
}
catch (Exception e)
{
e.printStackTrace();
}

Added my ip to the remote access host allowed ips. The error message I am getting is:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'jim'@'196.215.89.%' to database 'X'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:935)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4101)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1300)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2337)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at test.main(test.java:17)

I think the problem is the url in the string, but I have no idea what else it could be:
String url = "jdbc:mysql://pcassemble.co.za:3306/X";
 
Last edited:
Is the port open and have you allowed access from your IP to the database?

xD realized now I didnt say wat was wrong. I googled my ip, and then went into remote access and took my ip then removed the last 3 digits and replaced it with %. (E.G xxx.xxx.xxx.%).

I have edited my op and added the error message.
 
"Access denied for user 'jim'@'196.215.89.%' to database 'X'"

i.e.

- You have connectivity to MySQL (Good)
- MySQL seems to allow connections from other than localhost (Good)
- You do not have permissions for the specific user for the specific host (Bad)

You will need to get access to your mysql and run something in the line of ..
"grant all privileges on X.* to 'jim'@'%' identified by 'pwd';"
"flush privileges"

http://dev.mysql.com/doc/refman/5.1/en/grant.html
 
Generally on a shared hosting account your username will be in the format of <control panel username>_<DB username>, and the same applies to the DB name: <control panel username>_<DB Name>

So you should use something like:


URL: pcassemble.co.za
Database: pcassemb_X
User: pcassemb_jim
Password: pwd


Just confirm what the actual values are by logging into your control panel, and then goto the MySQL Dabases section, it will show you what the actual values are.

Also, to make remote access easier, register a free DynDNS address and use that DynDNS address for your remote access host
 
Direct remote access to a database is not recommend. Rather telnet to the host and do whatever you need to do from there. Public access should only be via a front end application which limits what can be done and viewed.
 
Direct remote access to a database is not recommend.
And why not?

Rather telnet to the host and do whatever you need to do from there.
You're kidding right? You do realize that Telnet is SUPER insecure or are you just oblivious to it? Or are you trolling purposefully?

Public access should only be via a front end application which limits what can be done and viewed.
And if you read the full post you'll see that he had to grand remote host access through a control panel.
 
Thanks for all the help guys, got it working. It turns out that it was that the user didnt have privileges (I added the user to the wrong database xD).
 
Top
Sign up to the MyBroadband newsletter
X