title: java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES)
body: <p>I am trying to write into a mysql database from Java but I get this error:</p>
  
  <pre><code>java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES)
  </code></pre>
  
  <p>I am connecting to a local mysql instance and to be honest I don't know what's 172.17.0.1 ip.</p>
  
  <p>The small code I wrote:</p>
  
  <pre><code>public static void writeToDB(String value, String unit) throws ClassNotFoundException, SQLException, SQLException
  {
  
      // create a mysql database connection
      String myDriver = "com.mysql.cj.jdbc.Driver";
      String myUrl = "jdbc:mysql://localhost:3306/MyDB";
      Class.forName(myDriver);
  
      Connection conn = null;
  
      conn = DriverManager.getConnection(myUrl, "root", "MyPass");
  
  
      // the mysql insert statement
      String query = " insert into data (unit, value)"
              + " values (?, ?)";
  
      // create the mysql insert preparedstatement
      PreparedStatement preparedStmt = null;
      preparedStmt = conn.prepareStatement(query);
      preparedStmt.setString (1, unit);
      preparedStmt.setString (2, value);
  
      // execute the preparedstatement
      preparedStmt.execute();
      conn.close();
  
  }
  </code></pre>
  
  <p>I ran</p>
  
  <pre><code>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPass' WITH GRANT OPTION;
  </code></pre>
  
  <p>but nothing changed. </p>
  
  <p>My my.cnf is all commented out.
  My local ip is 192.168.1.46. I tried to use this ip and 127.0.0.1 instead of localhost on the myUrl variable but nothing changed.</p>
  
  <p>I restarted the mysql server, eclipse and pc without success. </p>
  
  <p>Edit: additional info
  I stopped the server and ran the code. I get the exact same exception. I guess somehow I can't reach the server at all.</p>
  
  <p>I am able to use "localhost" in my Python script. It writes on the same table as the java code. </p>