PythonAnywhere Forums

Flask MySQL database connectivity

I am a beginner at python ,I have been trying to connect to SQL since days using Flask ,no virtual environment

This is the error I am getting

{"error": "(1044, \"Access denied for user 'ANU95'@'%' to database 'BucketList'\")"}

My file

 from flask import Flask ,render_template, request,json
 from werkzeug import generate_password_hash, check_password_hash
 from flaskext.mysql import MySQL

  app = Flask(__name__)
  app.config["DEBUG"] = True
  mysql = MySQL()

  # MySQL configurations
  app.config['MYSQL_DATABASE_USER'] = 'ANU95'
  app.config['MYSQL_DATABASE_PASSWORD'] = 'Anuradha'
  app.config['MYSQL_DATABASE_DB'] = 'BucketList'
  app.config['MYSQL_DATABASE_HOST'] = ''

    def hello_world():
             # # wait a long time for the Mysql connection to timeout
             # cur = db.query(sql)

             return render_template('index.html')

     def showSignUp():
            return render_template('signup.html')

      def signUp():
                  _name = request.form['inputName']
                   _email = request.form['inputEmail']
                  _password = request.form['inputPassword']

             # validate the received values
             if _name and _email and _password:

                    conn = mysql.connect()
                    cursor = conn.cursor()
                    _hashed_password = generate_password_hash(_password)
                     data = cursor.fetchall()

                     if len(data) is 0:
                            return json.dumps({'message':'User created successfully !'})
                             return json.dumps({'error':str(data[0])})
                            return json.dumps({'html':'<span>Enter the required fields</span>'})

             except Exception as e:
                      return json.dumps({'error':str(e)})

Hello ANU95, welcome to PythonAnywhere! For your database name, we have prefixes. Take a look at your databases page. Your database name should look something like this: ANU95$BucketList.

Therefore, this should work.

app.config['MYSQL_DATABASE_DB'] = 'ANU95$BucketList'

PS: Please change your database password, others may use it to access your database contents since you posted it on the forums.