Reputation: 22995
I am having an issue with creating and grating permissions to a user using phpMyAdmin. I am having a Java swing application and it need to connect to this database.
How I created the user and granted the permission are below, step by step.
Add New User
Any Host
as the host (so the % is displayed in its text box), and mention the password. Any host
is because remote access required.Select
under Global Privileges
- Data
Go
Users
tab starting page again. Edit Privileges
on my newly created user.Database-specific privileges
Database-specific privileges
, Data
section.Go
Now, whenever my Java application connects to this, it gives the below error
java.sql.SQLException: Access denied for user 'userName'@'localhost' (using password: YES)
This is how I connect to the database, in my Java application
con = DriverManager.getConnection("jdbc:mysql://"+ip+":3306/databaseName","user","password");
Here,for the variable ip
, I tried both localhost
and 127.0.0.1
but still no good. What have I done wrong?
I noticed the connection works fine if I select Localhost
instead of Any Host
in step 4.
Upvotes: 0
Views: 2339
Reputation: 27
Have you set any password for the phpmyadmin. if yes please include that in the password field.or you can try lik this
con = DriverManager.getConnection("jdbc:mysql://"+ip+":3306/databaseName","localhost","");
Upvotes: 0
Reputation: 803
sometimes, mysql server doesn't get a 'localhost' from a local connection, you should try :
GRANT ALL PRIVILEGES ON database_name TO 'userName'@'theHostName' IDENTIFIED BY 'password';
or in a more risky way:
GRANT ALL PRIVILEGES ON database_name TO 'userName'@'%' IDENTIFIED BY 'password';
and finally
FLUSH PRIVILEGES;
Upvotes: 0
Reputation: 1004
Upvotes: 1
Reputation: 6965
You need to grant permissions to the userName@localhost in mysql.
GRANT ALL PRIVILEGES ON database_name TO userName@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Upvotes: 0