title: MySQL Python client got 1045 (28000): Access denied for user 'root'@'localhost'
body: <p>This error happens to both <code>pymysql</code> and <code>mysql-connector-python</code>. But not to the MySQL shell. MySQL shell is able to login via <code>mysql -u root -p</code> normally.</p>
  
  <p>The error looks like:</p>
  
  <pre><code>In [1]: import mysql.connector
  
  In [2]: mydb = mysql.connector.connect(
     ...:   host="localhost",
     ...:   user="root",
     ...:   passwd="password"
     ...: )
  
  ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>In [8]: import pymysql.cursors
  
  In [9]: connection = pymysql.connect(host='localhost',
     ...:                              user='root',
     ...:                              password='password',
     ...:                              db='db',
     ...:                              cursorclass=pymysql.cursors.DictCursor)
  
  ...
  OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
  </code></pre>
  
  <p>Python version 3.7, running on Mac OSX 10.14. MySQL version 8.0.16.</p>