Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get authorized using MySql?

 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run MySql under Solaris 8 very well. I inserted a user called jack into the user table
of mysql database like this:
mysql>INSERT INTO user (Host, User, Password)
-> VALUES('localhost', 'jack', PASSWORD('johnson'));
Query OK, 1 row affected (0.00 sec)
I checked the table, and see that user jack is there.
Here is a part of my JDBC test code, which accesses the demodb database I have created for test use.
import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.*;
class MySqlTest
{ public static void main(String [] args)
{ try
{ Class.forName ("org.gjt.mm.mysql.Driver");
java.sql.Connection con;
con=DriverManager.getConnection("jdbc:mysql://localhost/demodb", "jack", "johnson");
......
}
The code compiles successfully, but when I run the bytecode, I get an exception. Look here:
# java MySqlTest
java.sql.SQLException: Invalid authorization specification: Access denied for user: 'jack@localhost' (Using password: YES)
#

Don't worry about the driver. I think the driver is working well, otherwise, I would have got another exception concerning the driver.
So what is the problem? How should I fix it please?
Thanks a lot.
[ March 10, 2002: Message edited by: Gene Chao ]
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must add jack@localhost in your access table. In my system, the domain added by the commandline tool is "username@localhost.localdomain" or username@real_host_name
I suggest you to log in from the commandline utility and explicitly run the following:
mysql> GRANT ALL PRIVILEGES ON *.* TO jack@localhost IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. How do I add that thing to the access table? What do you mean by access table? Are you referring to the user table of mysql database? Thanks.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I meant the user table. I think the above GRANT command should take care of this for you ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic