OperationalError:(1045,“拒绝访问用户'root'@'localhost'(使用密码:NO)”)

时间:2015-01-13 13:58:23

标签: python mysql flask

我正在尝试学习flask-mysql using this link 但我得到某种类型的错误

from flask import Flask
from flaskext.mysql import MySQL
app = Flask(__name__)

mysql = MySQL()
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASEE_PASSWORD'] = 'root'
app.config['MYSQL_DATABASE_DB'] = 'EmpData'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

@app.route('/')
def index():
  return 'hello people'

@app.route("/Authenticate")
def Authenticate():
  username = request.args.get('UserName')
  password = request.args.get('Password')
  cursor = mysql.get_db().cursor()
  cursor.execute("SELECT * from User where Username='" + username + "' and Password='" + password + "'")
  data = cursor.fetchone()
if data is None:
 return "Username or Password is wrong"
else:
 return "Logged in successfully"

if __name__ == "__main__":
 app.run(debug = True)

帮我理解这个问题 在终端:     mysql -u root -p     ;密码:root

1 个答案:

答案 0 :(得分:2)

错误在这里 - > app.config['MYSQL_DATABASEE_PASSWORD'] = 'root'

更正app.config['MYSQL_DATABASE_PASSWORD'] = 'root'的密钥,即从E删除额外的MYSQL_DATABASEE_PASSWORD字符。