0

I am trying to connect to my database which is hosted on 000webhost. I am connecting from SmartFoxServer, and they allow database connections. All you have to do is change some of the settings in the smartfoxserver xml file.

I have successfully managed to connect to my localhost mysql database using these settings.

 <databaseManager active="true">
    <connectionString>jdbc:mysql://localhost:3306/db_name</connectionString>
    <userName>root</userName>
    <password></password>
    <testSql>SELECT id FROM users LIMIT 1</testSql>
  </databaseManager>

But when I tried to connect to my external database which is hosted on 000webhost and looks like this:

enter image description here

Using these settings

<connectionString>jdbc:mysql://mysql2.000webhost.com/a5939459_data</connectionString>
<userName>a5939459_user</userName>
<password>censored</password>
<testSql>SELECT id FROM users LIMIT 1</testSql>

I get the following error...

Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
Message: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driv
er has not received any packets from the server.
Description: The DBManager Test SQL failed
Please double check your SQL code and make sure that Database server is running.

EDIT:

But when I run php files on my localhost and ask for database connection like this, it works

<?php
$db_username = "a5939459_user";
$db_name = "a5939459_data";
$db_password = "censored";
$db_host = "mysql2.000webhost.com";
mysql_connect($db_host,$db_username, $db_password, $db_name);
mysql_select_db($db_name) or die (mysql_error());
?>
Pierre.Vriens
  • 1,159
  • 34
  • 15
  • 19
Joe Slater
  • 127
  • 1
  • 7

3 Answers3

0

The MySQL host they give you has a 10. IP address, which is unroutable on the Internet. You can only connect to that host from the web host they provide, not from another host.

John
  • 9,070
  • 1
  • 29
  • 34
  • At the moment, my smartfox server is on my laptop, but at the end I am going to upload it to my remote server on amazon ec2. But my mysql database will be on webhost? Will it work? – Joe Slater Feb 22 '13 at 15:26
  • I do not understand you fully, do you mean I can not access mysql database from anywhere else except from the files that are uploaded on the webhost? – Joe Slater Feb 22 '13 at 15:29
  • No. Your EC2 instance will not be able to get to the mysql2.000webhost.com server to talk to the database. Only the 000webhost web server can talk to that database server. – John Feb 22 '13 at 15:29
  • Plz look at the edit. – Joe Slater Feb 22 '13 at 15:35
0

It is a big security issue to open up a database/mysql port for external/Internet connections. So when they created your database, they will most likely assign a user to connect only from limited source IPs, mostly Internal IPs. You need to communicate with their support for information from which source IPs you are allowed to connect. As John mentioned, the mysql2.000webhost.com resolves to a private IP address, and that implies you are most likely allowed to connect to it from some other private IP, which you might connect to through VPN or other means.

mysql2.000webhost.com.  14189   IN      A       10.1.1.102
Daniel t.
  • 9,291
  • 1
  • 33
  • 36
  • Plz look at the edit – Joe Slater Feb 22 '13 at 15:34
  • Oh, I can connect through php files because they do not require port but jdbc requires port? Is that the reason? – Joe Slater Feb 22 '13 at 15:50
  • yes for jdbc you will need the port number - `jdbc:mysql://mysql2.000webhost.com:3306` – Daniel t. Feb 22 '13 at 15:52
  • I tried with port number but I still get the same error. Do you know solution to this problem? What options do I have from here? – Joe Slater Feb 22 '13 at 15:54
  • http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql – Daniel t. Feb 22 '13 at 15:56
  • http://members.000webhost.com/panel/faq.php?ID=27&accountID=11919706&login_hash=2TODdDDg3MQkmF9v Oh god why, I have made my whole freaking website here, do you know what will be the simplest solution from here ... changing webhost or is there a simpler solution here? – Joe Slater Feb 22 '13 at 16:04
  • http://www.freemysql.net/ found this. Does this allow free external mysql connections without having to change my webhost? I am not sure if this is what I am looking for, so asking confirmation from you. Sry, I am a newb. Thanks very very much. – Joe Slater Feb 22 '13 at 16:16
  • Ankur, mysql remote connection is a BAD idea, security as well as performance wise. But if you insist simply contact their support and ask them if they allow remote connection or google for 'mysql database hosting with remote-access'. That is as far as i can help. – Daniel t. Feb 22 '13 at 16:21
0

As pointed by others, the problem was indeed that 000webhost does not allow remote connections to mysql databases.

http://www.freesqldatabase.com/

Ended up using this for my mysql databases. It is free. It is actually quite reliable and fast. Has free remote connections allowed. Has phpMyAdmin.

Not sure about the security though, but otherwise a great alternative.

Joe Slater
  • 127
  • 1
  • 7