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.
- Open phpMyAdmin
- Go to 'Users' tab.
- Click on
Add New User
- Give the user name, select
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
Select
underGlobal Privileges
-Data
- Click on
Go
- Now I am in the
Users
tab starting page again. - Click on
Edit Privileges
on my newly created user. - Select the database under
Database-specific privileges
- Tick everything under
Database-specific privileges
,Data
section. - Click on
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.