title: mysql Access denied for user root@localhost (using password: NO) despite having set a password and entered it in connection uri
body: <p>I'm trying to configure a mysql db with pymysql and Flask-sqlalchemy in a flask app.</p>
  
  <pre><code>db = SQLAlchemy()
  app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:password@localhost:3306/ftm'
  db.init_app(app)
  </code></pre>
  
  <p>However, when I run my app, I get:</p>
  
  <pre><code>OperationalError: (pymysql.err.OperationalError) (1045, u"Access denied for user 'root'@'localhost' (using password: NO)")
  </code></pre>
  
  <p>I tried resetting the password, and verified that it works: from command line, I can enter mysql by writing: </p>
  
  <pre><code>mysql -u root -p
  </code></pre>
  
  <p>And then entering my password at the prompt. Does anybody have any insight as to why mysql seems to think I'm trying to connect without a password, even though I have a (valid) password in the URI?</p>
  
  <p>Note that this is a different problem from <a href="https://stackoverflow.com/questions/10181344/mysql-exceptions-operationalerror-1045-access-denied-for-user-rootlocalh">mysql_exceptions.OperationalError: (1045, &quot;Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)&quot;)</a> and other potential duplicates because those error messages at least register that the connection attempt has a password attached.</p>
  
  <p>Edit: In no particular order, I have: <strong>tried a different user</strong>, <strong>checked the state of the connect string</strong> immediately before db.init_app, created a <strong>different instance of MySQL</strong> and tried connecting to it, <strong>removed pymysql</strong> from the connection string, and tried <strong>back tracing it with pdb</strong> (useless because the only method call which I recognized as my own was init_app()). I have also scoured the internet, and found <strong>no mention of anybody getting this error message when trying to connect to the database using a password.</strong> The only remaining possibility that I can think of is that <strong>while being passed from app.config to mysql (when I call db.init_app) something is changing my string to remove the password.</strong> Any ideas? If nobody’s got any, I’ll just have to go use Postgre or something…</p>