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

后端 未结 5 1497
挽巷
挽巷 2021-01-21 14:15

I\'m having troubles with my project , it involves JDBC and Mysql connection .

When I do the following :

private Statement m_         


        
相关标签:
5条回答
  • 2021-01-21 14:49

    Either the username/password is wrong or the user is missing privileges to access the schema/table. Grant privileges using

    GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION

    0 讨论(0)
  • 2021-01-21 14:54

    TO check if mysql has a password, go to the directory where you installed mysql, and in the bin directory try to bring up mysql prompt using

    ./mysql –u root mysql

    If the login goes through without any problem, it means no password is set.
    You can use mysqadmin script to set/reset password.

    ./mysqladmin –u root password "password string"

    0 讨论(0)
  • 2021-01-21 14:55

    I encounter the same error, this is how I fixed it:

    I used DriverManager class like this:

        Class.forName("com.mysql.jdbc.Driver");
        Connection Hello = DriverManager.getConnection("jdbc:mysql://YOUR-URL-HERE", "USERNAME", "PASSWORD");
    

    And that's it. Also, when selecting a table, remenber to put the DB name first, like:

        "DB_NAME.TABLE_NAME".
    
    0 讨论(0)
  • 2021-01-21 14:56

    Looks like you've only just installed mysql. Run mysql_secure_installation. It will prompt you for a root password, among other things.

    0 讨论(0)
  • 2021-01-21 15:06

    I had the same problem. You need to set a password for the user. Go to the mysql console .

    $ mysqladmin -u root password myFirstpassword
    

    Then change your password in the java program

    0 讨论(0)
提交回复
热议问题