This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes strange problem when accessing MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "strange problem when accessing MySQL" Watch "strange problem when accessing MySQL" New topic
Author

strange problem when accessing MySQL

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi,

I am getting a problem with MySQL, which I am not able to figure out, Why.

When I access MySQL with it's command line client, it asks me just password which I give 'admin' and it works (I might have given this at the time of installation).

But when I go into [MySql Home]\bin directory through command prompt and run following command:

mysql -h localhost -u admin -p admin

It asks me password (why again?), and when I give 'admin', it gives following error:

ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)

Note: I am not sure if I gave 'admin' as username while installation.

What can be the problem?

Thanks.
[ January 22, 2008: Message edited by: ankur rathi ]
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
As I guessed, the username and password combination was not correct. So I changed the command:

mysql -h localhost -u root -p admin

Now it gives following error:

ERROR 1049 (42000): Unknown database 'admin'

I have no clue, what is this error? How to solve?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Now I run this command:

mysql -u root -p mysql

It asks password, which I give 'admin' and it works.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
But I am confused. Why is it asking password again?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Now when I run following program using JDBC API:



It gives this exception:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

No idea, what all is happening? I should go home now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Why is it asking for the password? Because it interprets the -p tag as meaning a password will follow.
Pankaja Shinde
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
Problem is at your end.
I got correct results for the queries that you mentioned.

Pankaj Shinde
SCJP
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Campbell Ritchie:
Why is it asking for the password? Because it interprets the -p tag as meaning a password will follow.


That's what my one of the questions.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Pankaja Shinde:
Problem is at your end.

Pankaj Shinde
SCJP


But exactly where?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Guys, I solved the problem.

1. First I connected with 'root' user through command prompt:

mysql -u root -p mysql

It asks for password which I gave 'admin'.

Now I am logged in.

2. Then, I created another user with all privilege:

GRANT ALL PRIVILEGES ON *.* TO 'ankur'@'localhost' IDENTIFIED BY 'secret' WITH GRANT OPTION;

It creates user 'ankur' (password 'secret') which has all the permission.

Now the program:



And it worked.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Great Ankur! Congrats :thumb:

I had also faced these issues and resolved through google search and Mysql Documentation.

Ultimately the grant option worked


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
jQuery in Action, 2nd edition
 
subject: strange problem when accessing MySQL
 
Similar Threads
Unable to access admin console of tomcat
401 Error of Tomcat
Error in Hibernate url for mysql ?
MySql Password error
MySQL Error