title: sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
body: <p>So i am trying to build a simple blog website where i am using Flask and flask_sqlalchemy.
  Here i am trying to add the information ( Name,email id etc) <a href="https://i.stack.imgur.com/q5F8d.png" rel="nofollow noreferrer">UI part</a> and then on button click , it will save to localhost/phpMyadmin.</p>
  <p>Here it is Main.py file</p>
  <pre><code>from flask import Flask , render_template ,redirect, url_for, request
  from flask_sqlalchemy import SQLAlchemy
  
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/PersonalBlog'
  
  # initialize
  db = SQLAlchemy(app)
  
  # To Db
  class PostTable(db.Model):
      sno = db.Column(db.Integer, primary_key=True, unique=True, nullable=False)
      date = db.Column(db.DATE, primary_key=False)
      name = db.Column(db.String(120), unique=False, nullable=False)
      emailid = db.Column(db.String(50), unique=False, nullable=False)
      phone = db.Column(db.String(15), unique=False, nullable=False)
      message = db.Column(db.String(120), unique=False, nullable=False)
  
  @app.route(&quot;/&quot;)
  def home():
      return render_template('index.html')
  
  @app.route(&quot;/homeclick&quot;)
  def homeclick():
      return render_template('index.html')
  
  @app.route(&quot;/about&quot;)
  def about():
      return render_template('about.html')
  
  @app.route(&quot;/post&quot;)
  def post():
      return render_template('post.html')
  
  @app.route(&quot;/contact&quot; , methods=['POST', 'GET'])
  def contact():
      if request.method == 'POST' :
          # add entry to the database
  
          name = request.form.get('name')
          emailid = request.form.get('email')
          phone = request.form.get('phone_number')
          message = request.form.get('message')
  
          entry_to_db = PostTable(name=name, emailid=emailid , phone=phone, message=message)
          db.session.add(entry_to_db)
          db.session.commit()
      return render_template('contact.html')
  
  if __name__ == '__main__':
      app.run(debug=True, port=4013 , threaded=True)
  </code></pre>
  <p>The following error is getting displayed when i click on Submit button after giving details.</p>
  <p><strong>sqlalchemy.exc.OperationalError
  sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, &quot;Access denied for user 'root'@'localhost' (using password: NO)&quot;)
  (Background on this error at: <a href="http://sqlalche.me/e/14/e3q8" rel="nofollow noreferrer">http://sqlalche.me/e/14/e3q8</a>)</strong></p>
  <p><strong>Full Traceback Details if it helps</strong></p>
  <p>File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 3211, in _wrap_pool_connect
  return fn()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 307, in connect
  return _ConnectionFairy._checkout(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 767, in _checkout
  fairy = _ConnectionRecord.checkout(pool)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 425, in checkout
  rec = pool._do_get()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/impl.py&quot;, line 146, in <em>do_get
  self.<em>dec_overflow()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 70, in <strong>exit</strong>
  compat.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/impl.py&quot;, line 143, in _do_get
  return self._create_connection()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 253, in _create_connection
  return _ConnectionRecord(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 368, in <strong>init</strong>
  self.__connect()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 611, in <em><em>connect
  pool.logger.debug(&quot;Error on connect(): %s&quot;, e)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 70, in <strong>exit</strong>
  compat.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 605, in __connect
  connection = pool._invoke_creator(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/create.py&quot;, line 578, in connect
  return dialect.connect(*cargs, **cparams)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/default.py&quot;, line 584, in connect
  return self.dbapi.connect(*cargs, **cparams)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/MySQLdb/<strong>init</strong>.py&quot;, line 130, in Connect
  return Connection(*args, **kwargs)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/MySQLdb/connections.py&quot;, line 185, in <strong>init</strong>
  super().<strong>init</strong>(*args, **kwargs2)
  The above exception was the direct cause of the following exception:
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 2088, in <strong>call</strong>
  return self.wsgi_app(environ, start_response)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 2073, in wsgi_app
  response = self.handle_exception(e)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 2070, in wsgi_app
  response = self.full_dispatch_request()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 1515, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 1513, in full_dispatch_request
  rv = self.dispatch_request()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/flask/app.py&quot;, line 1499, in dispatch_request
  return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/main.py&quot;, line 48, in contact
  db.session.commit()
  File &quot;&quot;, line 2, in commit</p>
  <p>File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 1428, in commit
  self._transaction.commit(_to_root=self.future)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 829, in commit
  self._prepare_impl()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 808, in _prepare_impl
  self.session.flush()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 3298, in flush
  self._flush(objects)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 3438, in <em>flush
  transaction.rollback(<em>capture_exception=True)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 70, in <strong>exit</strong>
  compat.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 3398, in _flush
  flush_context.execute()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py&quot;, line 456, in execute
  rec.execute(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py&quot;, line 630, in execute
  util.preloaded.orm_persistence.save_obj(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py&quot;, line 209, in save_obj
  for (
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py&quot;, line 370, in <em>organize_states_for_save
  for state, dict</em>, mapper, connection in _connections_for_states(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py&quot;, line 1709, in _connections_for_states
  connection = uowtransaction.transaction.connection(base_mapper)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 626, in connection
  return self._connection_for_bind(bind, execution_options)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 735, in _connection_for_bind
  conn = self._parent._connection_for_bind(bind, execution_options)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/orm/session.py&quot;, line 747, in _connection_for_bind
  conn = bind.connect()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 3165, in connect
  return self._connection_cls(self, close_with_result=close_with_result)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 96, in <strong>init</strong>
  else engine.raw_connection()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 3244, in raw_connection
  return self._wrap_pool_connect(self.pool.connect, _connection)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 3214, in _wrap_pool_connect
  Connection.<em>handle_dbapi_exception_noconnection(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 2068, in <em>handle_dbapi_exception_noconnection
  util.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/base.py&quot;, line 3211, in _wrap_pool_connect
  return fn()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 307, in connect
  return _ConnectionFairy._checkout(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 767, in _checkout
  fairy = _ConnectionRecord.checkout(pool)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 425, in checkout
  rec = pool._do_get()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/impl.py&quot;, line 146, in <em>do_get
  self.<em>dec_overflow()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 70, in <strong>exit</strong>
  compat.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/impl.py&quot;, line 143, in _do_get
  return self._create_connection()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 253, in _create_connection
  return _ConnectionRecord(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 368, in <strong>init</strong>
  self.__connect()
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 611, in <em><em>connect
  pool.logger.debug(&quot;Error on connect(): %s&quot;, e)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 70, in <strong>exit</strong>
  compat.raise</em>(
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 207, in raise</em>
  raise exception
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/pool/base.py&quot;, line 605, in __connect
  connection = pool._invoke_creator(self)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/create.py&quot;, line 578, in connect
  return dialect.connect(*cargs, **cparams)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/sqlalchemy/engine/default.py&quot;, line 584, in connect
  return self.dbapi.connect(*cargs, **cparams)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/MySQLdb/<strong>init</strong>.py&quot;, line 130, in Connect
  return Connection(*args, **kwargs)
  File &quot;/Users/ranjankumar/Desktop/Folders/Project Flask/env/lib/python3.8/site-packages/MySQLdb/connections.py&quot;, line 185, in <strong>init</strong>
  super().<strong>init</strong>(*args, **kwargs2)
  sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, &quot;Access denied for user 'root'@'localhost' (using password: NO)&quot;)
  (Background on this error at: <a href="http://sqlalche.me/e/14/e3q8" rel="nofollow noreferrer">http://sqlalche.me/e/14/e3q8</a>)
  The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
  To switch between the interactive traceback and the plaintext one, you can click on the &quot;Traceback&quot; headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.</p>
  <p>You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:</p>
  <p>dump() shows all variables in the frame
  dump(obj) dumps all that's known about the object</p>