title: Mysql connecting ok with local host but not connecting with ip address
body: <p>I have a java program which takes its information from MySQL it works fine when I use localhost to connect to it but whenever i put ipaddress in it it does not work.
  My connection code and exception are as follows.</p>
  
  <pre><code>package connection;
  
  import java.net.InetAddress;
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  /**
   *
   * @author rpsal
   */
  public class DBConnection {
  
      public static Connection connect()//working  on local host
      {
          Connection conn = null;
          try {
              Class.forName("com.mysql.jdbc.Driver");
              String url = "jdbc:mysql://"+getIpAddress()+"/ChatMaster";
              conn = DriverManager.getConnection(url, "root", "");
          } catch (Exception e) {
              System.out.println("Exception in connect" + e);
          }
          return conn;
      }
  
      public static String getIpAddress() throws Exception {
          InetAddress inetAddress = InetAddress.getLocalHost();
          return inetAddress.getHostAddress();
      }
  }
  </code></pre>
  
  <p>When i use <code>String url = "jdbc:mysql:///ChatMaster";</code> it works fine.
  The exception i am getting is as follows.</p>
  
  <pre><code>Exception in connectjava.sql.SQLException: null,  message from server: "Host 'Rp-Salh' is not allowed to connect to this MySQL server"
  </code></pre>