• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange problem when accessing MySQL

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I run this command:

mysql -u root -p mysql

It asks password, which I give 'admin' and it works.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I am confused. Why is it asking password again?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48374
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it asking for the password? Because it interprets the -p tag as meaning a password will follow.
 
Pankaja Shinde
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem is at your end.
I got correct results for the queries that you mentioned.

Pankaj Shinde
SCJP
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pankaja Shinde:
Problem is at your end.

Pankaj Shinde
SCJP


But exactly where?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Ankur! Congrats :thumb:

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

Ultimately the grant option worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic