Reputation: 6260
I have a java code and I am connecting to the mysql database with the following connection string.
String userName = "admin";
String password = "pass";
String url = "jdbc:mysql://<my IP>/dbase"; //not localhost
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
When I make a JAR (Runnable JAR through eclipse), and take it to another machine in the same network I get an error
Access denied for user 'admin'@'<another machine IP' (using password: YES) //not localhost
The IP magically changed to another machine IP when I take the JAR to another machine. admin user has all privileges possible.
Whats wrong? Please help !!
Upvotes: 0
Views: 498
Reputation: 471
I think There is no problem with your Java code. Also try to connect the mysql server from command prompt
mysql -u root -h <ip address> -p
If you got the same error then the possible reason would be 1. In correct password 2. Permission is denied to access via network
You can give permission using below command
GRANT ALL ON db.* to root@'ip' IDENTIFIED BY 'PASSWORD';
Upvotes: 0
Reputation: 40
Maybe you should run the below command.
grant all privileges on *.* to 'admin'%'@' identified by 'pass';
flush privilges;
Upvotes: 2
Reputation: 76888
The IP address listed in the error message is the IP address of the machine your program is running on. It's telling you that you're not allowed to connect to MySQL from that IP address as root
You will need to talk to the person who configures/administers your MySQL database. More than likely this is an intentional security measure.
Upvotes: 4