简体   繁体   English

pymysql.err.OperationalError: (1045, “访问被拒绝用户 'MYID'@'localhost'(使用密码:NO)”)

[英]pymysql.err.OperationalError: (1045, “Access denied for user 'MYID'@'localhost' (using password: NO)”)

I am running a flask web server on server A, and I need to access a SQL database in remote server B.我在服务器 A 上运行 Flask Web 服务器,我需要访问远程服务器 B 中的 SQL 数据库。

I am getting this error.我收到此错误。

pymysql.err.OperationalError: (1045, "Access denied for user 'MYID'@'localhost' (using password: NO)")pymysql.err.OperationalError: (1045, “访问被拒绝用户 'MYID'@'localhost'(使用密码:NO)”)

Can someone help me??有人可以帮我吗??

Below is my code:下面是我的代码:

from flask import Flask, render_template, request
from flask.ext.mysql import MySQL

app = Flask(__name__)

app.config['MYSQL_HOST']='IP OF SERVER B'
app.config['MYSQL_PORT']='SERVER B PORT NUMBER'
app.config['MYSQL_USER']='MYID'
app.config['MYSQL_PASSWORD']='MYPW'
app.config['MYSQL_DB']='DBNAME'
mysql=MySQL(app)
mysql.init_app(app)
@app.route('/')
def index():
    cur = mysql.get_db().cursor()
    cur.execute('''SQLQUERY;''')
    rv=cur.fetchall()
    return str(rv)

Using a mysql client or console you should execute something like this:使用 mysql 客户端或控制台,您应该执行如下操作:

grant all privileges on DBNAME.* to MYID@localhost identified by 'MYPW';

using a user with grant privilege (usually root ).使用具有授予权限的用户(通常是root )。

Of course you can narrow down the privileges that you grant from: all privileges to let's say: select,insert,update,delete , depending on the case.当然,您可以缩小授予的权限: all privileges ,例如: select,insert,update,delete ,具体取决于具体情况。

To access the console with root open a terminal window and write:要使用 root 访问控制台,请打开终端窗口并写入:

mysql -uroot -p

and provide the password or for passwordless root:并提供密码或无密码root:

mysql -uroot

In case you do not know the root password follow this guide: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html如果您不知道 root 密码,请遵循本指南: https : //dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

In case you are on a company/university workstation with no privileges to perform the above operation, ask from the administrator to grant the privileges.如果您在公司/大学工作站上没有执行上述操作的权限,请向管理员请求授予权限。

try changing your尝试改变你的

app.config['MYSQL_HOST'] = ...

to

app.config['MYSQL_DATABASE_HOST'] = ...

this applies to the rest as well:这也适用于其余部分:

MYSQL_DATABASE_HOST default is ‘localhost’
MYSQL_DATABASE_PORT default is 3306
MYSQL_DATABASE_USER default is None
MYSQL_DATABASE_PASSWORD default is None
MYSQL_DATABASE_DB   default is None
MYSQL_DATABASE_CHARSET  default is ‘utf-8’

I had the same problem but this fixed it for me.我有同样的问题,但这对我来说解决了。 Hope this helps you as well.希望这对你也有帮助。 Look at the Flask MySQL reference here此处查看 Flask MySQL 参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python不连接mysql。 pymysql.err.OperationalError:(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:NO)”) - python doesn't connect mysql. pymysql.err.OperationalError: (1045, “Access denied for user 'root'@'localhost' (using password: NO)”) OperationalError:(1045,“拒绝用户'root'@'localhost'的访问(使用密码:是)”) - OperationalError: (1045, “Access denied for user 'root'@'localhost' (using password: YES)”) OperationalError: (1045, “用户 'rajendra'@'localhost' 的访问被拒绝(使用密码:NO)”) - OperationalError: (1045, "Access denied for user 'rajendra'@'localhost' (using password: NO)") OperationalError:(1045,“拒绝用户'root'@'localhost'的访问(使用密码:NO)”) - OperationalError: (1045, “Access denied for user 'root'@'localhost' (using password: NO)”) MySQLdb._exceptions.OperationalError OperationalError:(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:是)”) - MySQLdb._exceptions.OperationalError OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") sqlalchemy.exc.OperationalError:(MySQLdb._exceptions.OperationalError)(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:NO)”) - sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, “Access denied for user 'root'@'localhost' (using password: NO)”) django.db.utils.OperationalError: (1045: Access denied for user 'root'@'localhost' (using password: NO) - django.db.utils.OperationalError: (1045:Access denied for user 'root'@'localhost' (using password: NO) 无法在Google CloudSQL OperationalError 1045上运行syncdb,使用密码:用户'root'@'localhost'拒绝访问 - Can't run syncdb on Google CloudSQL OperationalError 1045 Access denied for user 'root'@'localhost' using password: NO Django OperationalError,位于/(1045,“拒绝用户'root'@'localhost'的访问(使用密码:是)”) - Django OperationalError at / (1045, “Access denied for user 'root'@'localhost' (using password: YES)”) sqlalchemy.exc.OperationalError:(MySQLdb._exceptions.OperationalError)(1045,“用户'taran'@'localhost'的访问被拒绝(使用密码:是)”) - sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'taran'@'localhost' (using password: YES)")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM