0

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 !!

8
  • You are trying to access the database from the other machine ip. Therefore the error is correct. Is your MySQL server configured to allow access from that IP? Commented Jan 11, 2012 at 1:59
  • Have you hardcoded your IP there? Commented Jan 11, 2012 at 1:59
  • 1
    why is that root is on the error message where in fact userName = admin? even if it changes its IP, the username will still be admin not root. Commented Jan 11, 2012 at 2:00
  • @johntotetwoo - the default root user for MySQL is admin Commented Jan 11, 2012 at 2:04
  • @thinksteep yes I have hardcoded the IP in my program. The IP changes in the other machine Commented Jan 11, 2012 at 2:14

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Brian. I am sure this is the problem. I'll consult my DBA tomorrow
2

Maybe you should run the below command.

grant all privileges on *.* to 'admin'%'@' identified by 'pass';
flush privilges;

Comments

0

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.