Dear all,
I am having a hard time connect mysql with Java.
I am using the code like this:
Connection db;
try {
db = DriverManager.getConnection("jdbc:mysql://localhost/project",
user, pass);
}
where project is my database.
There is no problem with the driver Class.forName("com.mysql.jdbc.Driver");
However, for some reason I get this error message:
java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"
Should I specify a socket or something like that in order to reach a
connection to my localhost?
thanks for your help,
Marcelo
Seamus - 22 Nov 2005 16:26 GMT
> Dear all,
>
[quoted text clipped - 21 lines]
>
> Marcelo
Take a look at this thread on the mysql site :
http://forums.mysql.com/read.php?86,23619,41248#msg-41248
Roedy Green - 22 Nov 2005 18:57 GMT
>java.sql.SQLException: null, message from server: "Host
>'localhost.localdomain' is not allowed to connect to this MySQL server"
>
>Should I specify a socket or something like that in order to reach a
>connection to my localhost?
It sounds like you need some sort of GRANT statement to allow access
from that domain. I did not see a syntax for that though.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Marcelo - 22 Nov 2005 20:31 GMT
hi,
I am still having trouble with this connections. Even after using the
Grant command (with parameter ALL) it is impossible to accès to the
database.
I seems like localhost is not recognised.... (i have even tried
127.0.0.1 no difference).
I don't have any idea of how may be wrong....
if you have some ideas, please let me know
Marce
zero - 22 Nov 2005 20:51 GMT
> hi,
>
[quoted text clipped - 9 lines]
>
> Marce
Who did you grant all privileges to?
It seems like your problem is with the MySQL administration, not Java. I
suggest you ask at a mysql group. Before you do, you could do some
testing, like trying to connect (from localhost of course) with the mysql
command line client.
Marcelo - 22 Nov 2005 21:06 GMT
normally it works on command line
mysql -h localhost -u anyone -p any
On command line, no problem at all.
the grant privileges where given by the "root" user.
thanks
Marcelo
Marcelo - 22 Nov 2005 20:54 GMT
> hi,
>
[quoted text clipped - 9 lines]
>
> Marce
I am using this driver, is it okay?
Class.forName("com.mysql.jdbc.Driver");
Rhino - 22 Nov 2005 21:17 GMT
>> hi,
>>
[quoted text clipped - 12 lines]
> I am using this driver, is it okay?
> Class.forName("com.mysql.jdbc.Driver");
Yes, that is the correct JDBC driver to use for MySQL.
There are several MySQL mailing lists at this URL: http://lists.mysql.com/.
One of them is dedicated to Java/MySQL questions. You may want to check the
archive for that list to see if they've seen this problem before and have a
solution. I just looked and this problem has come up several times before
and the responders have suggested solutions.
However, if you try everything suggested in the archives and still have
problems, you can subscribe to the mailing list and describe your problem
there. One of the guys who responds to the questions on the MySQL/Java
mailing list is a guy named Mark Matthews who writes the JDBC drivers for
MySQL; he is very helpful. But many of the other responders there are also
very good.
I'm not going to tell you what the archives give as the solution for your
problem. If you are going to work with MySQL, it's a very good idea for you
to get familiar with the best ways to get help with MySQL problems; you
won't get that if I do all of the work :-)
Rhino
Marcelo - 22 Nov 2005 21:52 GMT
I guess I have found the error, but I don't know well how to proceed (as
I am very new in SQL)
I guess there is a problem with the max_connections, max_updates values
at the mysql database given for the root
how to proceed know? (changing this value?)
thanks a lot,
Marcelo
Marcelo - 22 Nov 2005 21:53 GMT
> I guess I have found the error, but I don't know well how to proceed (as
> I am very new in SQL)
[quoted text clipped - 7 lines]
>
> Marcelo
+-----------+------------------+---------------+-------------+-----------------+
| host | user | max_questions | max_updates |
max_connections |
+-----------+------------------+---------------+-------------+-----------------+
| localhost | root | 0 | 0 |
0 |
| ubuntu | root | 0 | 0 |
0 |
| localhost | debian-sys-maint | 0 | 0 |
0 |
| localhost | anyone | 0 | 0 |
0 |
+-----------+------------------+---------------+-------------+-----------------+
Marcelo - 22 Nov 2005 22:15 GMT
I just wanna share this experience (it took me more than 3 hours :( )
there was no connection for two important reasons:
1.- the username created on localhost had as max_connections parameter = 0 (with other parameters) so when java wanted to connect to the mysql server, the connection has refused.
2.- for some reason that I don't understand, the localhost cannot be accessed by this java program
the error has:
java.sql.SQLException: null, message from server: "Host 'localhost.localdomain' is not allowed to connect to this MySQL server"
So I created the grants 'username'@'localhost.localdomain' and then, magickally, it worked. However, I don't understand why Mysql has asking for localhost.localdomain .....
thanks to everybody,
excellent help was given !!!!
Marcelo
Roedy Green - 22 Nov 2005 22:50 GMT
>I don't understand why Mysql has asking for localhost.localdomain .
On what machine the JDBC driver running, the same one as the SQL
engine right? So to SQL, that program is just another ordinary user
calling in from localhost.localdomain. It treats local connections
the same as those coming in over the net.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
jonck - 22 Nov 2005 23:03 GMT
> 1.- the username created on localhost had as max_connections
> parameter = 0 (with other parameters) so when java wanted to
> connect to the mysql server, the connection has refused.
No, this is not the cause of your problems. Contrary to what you might
think, having max_questions, max_updates and max_connections at 0 means
the user in question has unlimited questions, updates and connections.
Rhino - 23 Nov 2005 00:54 GMT
>I just wanna share this experience (it took me more than 3 hours :( )
>
[quoted text clipped - 12 lines]
> magickally, it worked. However, I don't understand why Mysql has asking
> for localhost.localdomain .....
This is explained in the archived posts that I mentioned in my original
reply to your question....
> thanks to everybody,
> excellent help was given !!!!
>
> Marcelo
Rhino
Alun Harford - 23 Nov 2005 01:21 GMT
> Dear all,
>
[quoted text clipped - 14 lines]
> java.sql.SQLException: null, message from server: "Host
> 'localhost.localdomain' is not allowed to connect to this MySQL server"
Did you forget to give it your password?
jdbc:mysql://localhost/project?user=USERNAME&password=PASSWORD
Alun Harford
Alun Harford - 23 Nov 2005 01:24 GMT
> > Dear all,
> >
[quoted text clipped - 20 lines]
>
> Alun Harford
Oh wait...
That was a dumb post (although it still looks like a password issue to me)
Alun Harford