views:

94

answers:

1

hi, I am trying to remotely access mySQL server. This is the code used by me.

 Connection conn = null; 
    try 
    { 
       String url = "jdbc:mysql://172.18.227.237:3306/struts2"; 
       Class.forName ("com.mysql.jdbc.Driver"); 
       conn = DriverManager.getConnection (url,"root","admin"); 
       System.out.println ("Database connection established"); 
    } 

But I get the following error:

 com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Access denied for user 'root'@'172.20.169.174' to database 'struts2'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.Connect.main(Connect.java:17)

I have been granted access permission to my IP, But yet I get error.

+1  A: 

Have you flushed the privileges after granting access to root at that IP? Privileges won't work until they have been loaded by the MySQL engine, so you have to issue a 'FLUSH PRIVILEGES' command.

Moo
This is not necessary if you used proper `CREATE USER` and `GRANT` commands - you need it only if you hack directly into the grant tables, which I would disrecommend
Roland Bouman