[英]PythonAnywhere error trying to access MySQL database (Access denied)
I have setup an environment in PythonAnywhere with a simple database (new_db), following all the guides and tutorials. 按照所有指南和教程,我已经在PythonAnywhere中设置了一个具有简单数据库(new_db)的环境。
I have a simple python Flask app which is trying to connect to the database using the following code: 我有一个简单的python Flask应用程序,它正在尝试使用以下代码连接到数据库:
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["DEBUG"] = True
SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
username="WazzalJohn",
password="my_password_here",
hostname="WazzalJohn.mysql.pythonanywhere-services.com",
databasename="WazzalJohn$new_db>",
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
db = SQLAlchemy(app)
But i keep getting the error: 但我不断收到错误:
ProgrammingError: (mysql.connector.errors.ProgrammingError) 1044 (42000): Access denied for user 'WazzalJohn'@'%' to database 'WazzalJohn$new_db>' ProgrammingError:(mysql.connector.errors.ProgrammingError)1044(42000):用户'WazzalJohn'@'%'对数据库'WazzalJohn $ new_db>的访问被拒绝
I have tried creating a new database but get the same problem. 我尝试创建一个新的数据库,但是遇到了同样的问题。 I thought PythonAnywhere handled all these types of issues so don't know what to do... has anyone had the same problem specifically on PythonAnywhere? 我以为PythonAnywhere处理了所有这些类型的问题,所以不知道该怎么办……有人在PythonAnywhere上有同样的问题吗?
I have now tried to log in through a BASH console and got similar message - screen shot is here 我现在尝试通过BASH控制台登录,并收到类似的消息-屏幕截图在此处
In your original code, you have an error in the database name: 在原始代码中,数据库名称有错误:
databasename="WazzalJohn$new_db>",
...should be: ...应该:
databasename="WazzalJohn$new_db",
...without the extra " >
". ...没有多余的“ >
”。
The problem in the screenshot is that you're not specifying a database on the command line; 屏幕快照中的问题是您没有在命令行上指定数据库; you need to do something like: 您需要执行以下操作:
mysql -u TWarren -h TWarren.mysql.pythonanywhere-services.com -p 'TWarren$default'
...where ' TWarren$default
' should be replaced with the actual database name. ...其中“ TWarren$default
”应替换为实际的数据库名称。 The single quotes around the database name are important, BTW -- if you don't use them, Bash will interpret " $default
" as an environment variable and mysql will try to connect to the wrong database. BTW数据库名称周围的单引号很重要-如果您不使用它们,Bash会将“ $default
”解释为环境变量,而mysql将尝试连接到错误的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.