Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes mySQl/JDBC error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "mySQl/JDBC error" Watch "mySQl/JDBC error" New topic

mySQl/JDBC error

William Joel

Joined: Sep 17, 2006
Posts: 2
Does anyone know why I would get this message when trying to connect to mySQL?

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

I have the latest drivers (jar files) and mysql has been configured such that localhost is granted all privileges.

Here is a code snippet:

[ September 17, 2006: Message edited by: William Joel ]

[ September 17, 2006: Message edited by: William Joel ]
[ September 17, 2006: Message edited by: William Joel ]
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Have you granted the root user access to mysql?

Take a look at the mysql manual for how to do this.

By the way, it's not a good practice to run any process as root or login to a database or other application as root. Root is a security risk so it's best to setup another, less privileged user account.
[ September 17, 2006: Message edited by: Scott Johnson ]
George Stoianov
Ranch Hand

Joined: Jan 15, 2006
Posts: 94
You probably have mistyped the password as root is root or are trying to connect right after the install using a password and by default it is blank.

Sometime in jdbc urls, depending on how localhost resolves, it is better to use the numeric IP equivalent instead of localhost.

The security concerns mentioned here are very much valid so create a user and a database connect on the command line/prompt and then try it in jdbc that way you will narrow down the problem.

Good luck.
I agree. Here's the link:
subject: mySQl/JDBC error
jQuery in Action, 3rd edition