title: Simple Flask app - can't connect to database on localhost?
body: <p>I am trying to follow this tutorial:<br>
  <a href="http://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972" rel="nofollow">http://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972</a></p>
  
  <p>I have the web app appearing, i can browse between pages and when I click "Sign up" after filling in details I get this error in python:</p>
  
  <pre><code>ERROR:__main__:Exception on /signUp [POST]
  OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
  </code></pre>
  
  <p>I'm not sure whats happening here, i have a database called "BucketList.db" in the app.py root folder. </p>
  
  <p>Is there a way to find out where is is getting stuck? or why it cannot connect to the db? I can connect directly to the database using Sqlite and it all seems fine so maybe something not right with how its accessed through localhost?</p>
  
  <p>Any help/guidance would be appreciated! Thanks!!</p>
  
  <pre><code>from flask import Flask, render_template, json, request
  from flask_mysqldb import MySQL
  from werkzeug import generate_password_hash, check_password_hash
  
  mysql = MySQL()
  app = Flask(__name__)
  
  # MySQL configurations
  app.config['MYSQL_DATABASE_DB'] = 'BucketList'
  app.config['MYSQL_DATABASE_HOST'] = 'localhost'
  app.config['MYSQL_DATABASE_PORT'] = '5002'
  mysql.init_app(app)
  
  @app.route('/')
  def main():
      return render_template('index.html')
  
  @app.route('/showSignUp')
  def showSignUp():
      return render_template('signup.html')
  
  
  @app.route('/signUp',methods=['POST','GET'])
  def signUp():
      try:
          _name = request.form['inputName']
          _email = request.form['inputEmail']
          _password = request.form['inputPassword']
  
          # validate the received values
          if _name and _email and _password:
  
              # All Good, let's call MySQL
              conn = mysql.connect()
              cursor = conn.cursor()
              _hashed_password = generate_password_hash(_password)
              cursor.callproc('sp_createUser',(_name,_email,_hashed_password))
              data = cursor.fetchall()
  
              if len(data) is 0:
                  conn.commit()
                  return json.dumps({'message':'User created successfully !'})
              else:
                  return json.dumps({'error':str(data[0])})
          else:
              return json.dumps({'html':'&lt;span&gt;Enter the required fields&lt;/span&gt;'})
  
      except Exception as e:
          return json.dumps({'error':str(e)})
      finally:
          cursor.close() 
          conn.close()
  
  if __name__ == "__main__":
      app.run(port=5002)
  </code></pre>