Another JDBC + MySQL problem

T

tobleron

Hi all,

I have code (I'm not show the whole code here):

String url = "jdbc:mysql://localhost:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

The code is run well. Also when I change to this :

String url = "jdbc:mysql://127.0.0.1:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

It can run well. But when i used IP like this :

String url = "jdbc:mysql://140.135.100.180:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

It can not works. FYI, there is no other part is changed, apache,
phpmyadmin, etc run well. Only the JDBC can not work with IP. Is there
any idea how to solve this problem ?
 
S

Silvio Bierman

tobleron said:
Hi all,

I have code (I'm not show the whole code here):

String url = "jdbc:mysql://localhost:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

The code is run well. Also when I change to this :

String url = "jdbc:mysql://127.0.0.1:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

It can run well. But when i used IP like this :

String url = "jdbc:mysql://140.135.100.180:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "root", "secret");

It can not works. FYI, there is no other part is changed, apache,
phpmyadmin, etc run well. Only the JDBC can not work with IP. Is there
any idea how to solve this problem ?

You probably have your MySQL server configured to only allow connections
from localhost.
 
T

tobleron

You probably have your MySQL server configured to only allow connections
from localhost.

So, how to configure MySQL to allow connections from other host ? BTW,
the IP in the "jdbc:mysql://IP" is the IP of MySQL machine wright ?
 
T

tobleron

So, how to configure MySQL to allow connections from other host ? BTW,
the IP in the "jdbc:mysql://IP" is the IP of MySQL machine wright ?

I just change the "localhost" with "140.135.100.180" which is MySQL's
IP, and I still working in the same machine of MySQL. I also add user
in the MySQL "root" and "%" for the host, but still can not work. If I
change back to "localhost" or "127.0.0.1", it can run well. So
confusing...
 
J

John B. Matthews

tobleron said:
tobleron wrote: [localhost works; IP address doesn't]
It can not works.

OP: What versions? What errors? What does your system administrator say?
So, how to configure MySQL to allow connections from other host ? BTW,
the IP in the "jdbc:mysql://IP" is the IP of MySQL machine wright ?

OP: See MySQL Server Administration, especially sections 5.1.2 & 5.4.4:

<http://dev.mysql.com/doc/refman/6.0/en/server-options.html>
 
L

Lew

tobleron said:
I just change the "localhost" with "140.135.100.180" which is MySQL's
IP, and I still working in the same machine of MySQL. I also add user

But it is not 'localhost'. IP addresses may map to the same physical node,
but that does not make them equivalent.
in the MySQL "root" and "%" for the host, but still can not work. If I
change back to "localhost" or "127.0.0.1", it can run well. So
confusing...

Try reading the MySQL documentation. It explains how to do this. Others have
already pointed out that MySQL handles localhost differently from other IP
addresses. It is a fairly well-documented product.

You should study up on how IP addresses work.

Also, is it possible that 140.135.100.180 is an external IP address, if you're
behind a firewall? For example, a computer could have an internal address of
192.168.1.121 but an external address of 177.66.221.14. (Arbitrary IP
addresses chosen for the sake of example.) The firewall handles the
translation when packets cross between the external and internal domains.
It's called "Network Address Translation", or "NAT".
 
S

Silvio Bierman

tobleron said:
So, how to configure MySQL to allow connections from other host ? BTW,
the IP in the "jdbc:mysql://IP" is the IP of MySQL machine wright ?

Read the f* manual. I know I did once. But once PostgreSQL became
Windows-friendly and I could run it on my dev machine (as opposed to
only the Linux deployment servers) I was more than happy to drop MySQL
and never look back. If I think back to the referential constraint
failures PG noticed when I tried to import the MySQL databases (stored
in InnoDB tables which are supposed to support referential integrity) I
still get cold chills. And then I am not even talking about the
performance gain with actual databases (10-25 Gb). So much for MySQL
being faster than PG. </rant>
 
T

tobleron

But it is not 'localhost'.  IP addresses may map to the same physical node,
but that does not make them equivalent.


Try reading the MySQL documentation.  It explains how to do this.  Others have
already pointed out that MySQL handles localhost differently from other IP
addresses.  It is a fairly well-documented product.

You should study up on how IP addresses work.

Also, is it possible that 140.135.100.180 is an external IP address, if you're
behind a firewall?  For example, a computer could have an internal address of
192.168.1.121 but an external address of 177.66.221.14.  (Arbitrary IP
addresses chosen for the sake of example.)  The firewall handles the
translation when packets cross between the external and internal domains.
It's called "Network Address Translation", or "NAT".

@Lew
I can access the mysql from another computer by using http://140.135.100.180/phpmyadmin
All websites also can be accessed from another computer by using
http://140.135.100.180/website
All firewalls are already stopped. So, i think it should be accessible
from another machine by using that IP.

@All
Do you think the problem is belong to mysql setting or JDBC setting or
network setting ?
 
T

tobleron

Here is the error message that I found on NetBeans :

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

The error just happened if I use IP, but if I use "localhost", no
error occurs. Any idea about this ?
 
S

Silvio Bierman

tobleron said:
@Lew
I can access the mysql from another computer by using http://140.135.100.180/phpmyadmin
All websites also can be accessed from another computer by using
http://140.135.100.180/website
All firewalls are already stopped. So, i think it should be accessible
from another machine by using that IP.

@All
Do you think the problem is belong to mysql setting or JDBC setting or
network setting ?

That is not accessing MySQL but PHP and your webserver. They on their
turn access MySQL from localhost. Firewalls are npt the issue, it is the
MySQL server itself. Now please read the manual.

Silvio
 
T

tobleron

That is not accessing MySQL but PHP and your webserver. They on their
turn access MySQL from localhost. Firewalls are npt the issue, it is the
MySQL server itself. Now please read the manual.

Silvio

@Silvio
I'm trying to changethe server name of mysql from "localhost" to
"140.135.100.180" but I can not find the my.ini or my.cnf file. FYI, I
installed mysql using XAMPP (http://www.apachefriends.org/en/
xampp.html). Do you know, where how to find those files ?
 
S

Silvio Bierman

@Silvio
I'm trying to changethe server name of mysql from "localhost" to
"140.135.100.180" but I can not find the my.ini or my.cnf file. FYI, I
installed mysql using XAMPP (http://www.apachefriends.org/en/
xampp.html). Do you know, where how to find those files ?


Hello Toblreon,

You should not try to change the server name. As always GIYF and you
should try

http://www.google.com/search?q=mysql+accept+remote+connections

which will reveal a lot of discussions about the topic. Note that the
solution both depends on the MySQL version you are using and on what
type of system you run it.

I figured it out for a couple of specific situations years ago but as I
already mentioned I have not used MySQL for some years now so I do not
have a quick answer for you.

Good luck.

Silvio
 
T

tobleron

Additional info :

I changed the IP into 140.135.100.179
I have modify the my.cnf file and set the bind-IP into 140.135.100.179
and restart mysql.
It still can not works.

I used windows command to access the mysql :
shell>>mysql -h 140.135.100.179 -u root -p
It can be accessed. All operation run well under windows command box.

I used another mysql machine on 140.135.100.150 and it can be accessed
very well using windows command box. But when I modify my Java code to
access the second mysql machine :
String url = "jdbc:mysql://140.135.100.150:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
con = DriverManager.getConnection(url, "user", "password");
It can not works. If I change into "jdbc:mysql://localhost:3306/dicom?
jdbcCompliantTruncation=false", it can works well. So I suspect that
the problem is in the JDBC, not in the mysql.

Any idea ?
 
T

tobleron

I already read and tried all suggested links above, but still no
progress. One interest thing I found is, I delete all mysql users from
user table. But when I run my Java application using "localhost"
connection, it still can run well ! So, it means there is not a user
privilege nor host allowance issue.

But if I change into IP, still, can not run.

Any idea ?
 
T

tobleron

UPDATE :

From my PC (windows) I can connect to another mysql server through
windows command terminal.
Also I can connect my mysql server (in my local PC) through windows
command terminal.

But I can not connect those mysql servers through NetBeans IDE using
their IPs. Is there a special setting or parameter of JDBC ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top