0

I am trying to deploy my application to another server, and while the JDBC connection worked in my machine, I couldn't get it to work with this mysql server.

Some information about the mysql server:

    select user(); 
    +----------------+
    | user()         |
    +----------------+
    | root@localhost |
    +----------------+

    mysql> show variables where Variable_name="port";
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port          | 3306  |
    +---------------+-------+

There is no password to login into the mysql with user localhost (mysql -u root will be enough to login)

I used the following statement to connect to the database

    DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/database_name", "root", ""));

But, It throws the following error

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

Any suggestions? Thanks.

unknown
  • 343
  • 3
  • 16
  • Uername or password or ipaddress(localhost) is wrong possible duplicate http://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno – LMK May 29 '14 at 09:07
  • You should set the password of db user – Macrosoft-Dev May 29 '14 at 09:09

3 Answers3

1

you need to in %MYSQL_INSTALL_PATH%/bin folder,using cmd and run:

mysqld -nt --skip-grant-tables
mysqladmin -u root flush-privileges password "NEW_PASSWORD"

and restart mysql service.

Vito
  • 1,080
  • 9
  • 19
1

Try setting a password for root user. It is very bad and insecure to have root user without credentials. This link will help

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • Thanks for a quick response. But isn't there any way that I connect to mysql server, who don't have a password set? Did DriverManager.getConnection() method only works for password protected mysql servers? – unknown May 29 '14 at 09:27
  • The problem here is you actually have a password for `root`. But, you are trying to connect without the password. that's why i suggested you to reset the password. – Keerthivasan May 29 '14 at 09:37
  • But I am able login to the server without providing a password - mysql -u root – unknown May 29 '14 at 10:33
  • 1
    Try sending the password as `null` – Keerthivasan May 29 '14 at 12:55
  • Thanks all for the help. I mark this one as an answer 'cause I didn't try sending the password as null, as I set up a password for mysql before going through that, and think, perhaps, it might work with password set as null. – unknown May 30 '14 at 14:19
1

Have you tried mysql -u root -p , with the password field not provided? I guess here's the problem "jdbc:mysql://localhost:3306/database_name", "root", "")); you used a "" as your password so I think you need to do this mysql -u root -p

Dog Ears
  • 9,637
  • 5
  • 37
  • 54
Engkid
  • 33
  • 5
  • There is no password needed to login to mysql. Its not the one troubling me. My problem is I couldn't connect to a mysql server (one having no password) in JDBC. – unknown May 29 '14 at 09:25