title: Python - Connect MySQL through localhost not working but 127.0.0.1 is working?
body: <p>I just setup a VPS with a Mysql Database on it. I'm able to log into the database in the SSH terminal with <code>mysql -uroot -p</code> however, the python file shown below is unable to form a connection, and errors with <code>Access denied for root@localhost (using password: YES)</code>. I'm confused as to why this is happening. I'm 100% sure my password is correct. I'm using mysql.connector</p>
  <p>Python file:</p>
  <pre class="lang-py prettyprint-override"><code>import mysql.connector
  
  mydb = mysql.connector.connect(
    host=&quot;localhost&quot;,
    user=&quot;root&quot;,
    password=&quot;pwd&quot;,
    database=&quot;db&quot;
  )
  
  mycursor = mydb.cursor()
  
  sql = &quot;INSERT INTO test (tests) VALUES (%s)&quot;
  val = (&quot;testing&quot;)
  
  mycursor.execute(sql, val)
  
  mydb.commit()
  </code></pre>
  <p>I'm a bit new to this DB and VPS stuff, so please bear with me if I don't understand on the first go.</p>
  <p>Thanks!</p>