[英]sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'taran'@'localhost' (using password: YES)")
I have started this today and received this over again and again and I have recreated the user also but it is not working.我今天开始这个并一次又一次地收到这个,我也重新创建了用户,但它不起作用。 Please help me to debug it.
请帮我调试一下。
This is my app.py这是我的应用程序.py
from flask import Flask, jsonify, render_template, request from flask_sqlalchemy import SQLAlchemy from datetime import datetime app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://taran:1234@localhost/flask' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class Post(db.Model): id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(50), nullable = False) body = db.Column(db.String(200), nullable = False) date = db.Column(db.DateTime(timezone=True), default=datetime.now()) @app.route('/', methods = ['GET', 'POST']) def home(): title = request.form.get('title') body = request.form.get('body') post = Post(title = title, body = body) db.session.add(post) db.session.commit() return render_template('index.html') if __name__ == "__main__": app.run(debug= True)
Please help请帮忙
check if the password to access your SQL database is correct or else try changing your SQL root password to something else and try again.检查访问 SQL 数据库的密码是否正确,或者尝试将 SQL 根密码更改为其他密码,然后重试。 The above error is very similar to the one we commonly encounter while logging on to a website with the wrong password or username.
上述错误与我们在使用错误的密码或用户名登录网站时经常遇到的错误非常相似。
for changing the root password see the below video https://youtu.be/izMuHGwXyjQ如需更改 root 密码,请参阅以下视频https://youtu.be/izMuHGwXyjQ
If you don't have a password try either of this如果您没有密码,请尝试其中任何一个
Option 01:选项 01:
SQLALCHEMY_DB_URI='mysql://root@localhost:<PORT>/<DB NAME>'
Option 02:选项 02:
SQLALCHEMY_DB_URI='mysql://root:''@localhost:<PORT>/<DB NAME>'
Have you tried to change the driver?您是否尝试过更改驱动程序?
#from
'mysql://taran:1234@localhost/flask'
#to
'mysql+pymysql://taran:1234@localhost/flask'
(I assume you've checked credentials already) (我假设您已经检查过凭据)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.