Mysql与Flask python 3.7的连接遇到一些问题

Mysql与Flask python 3.7的连接遇到一些问题,mysql,python-3.x,flask,Mysql,Python 3.x,Flask,环境: 在我的本地计算机上: Python 3.7.7 烧瓶1.1.2 Werkzeug 1.0.1 远程服务器: Ubuntu MariaDB 10.1.44 问题: 我正在本地计算机上开发一个带有Flask的web应用程序,它需要访问我的远程Mysql服务器。 我在浏览器上收到以下错误消息: MySQLdb._exceptions.OperationalError MySQLdb._exceptions.OperationalError: (1045, "Access denied

环境:

在我的本地计算机上: Python 3.7.7 烧瓶1.1.2 Werkzeug 1.0.1

远程服务器: Ubuntu MariaDB 10.1.44

问题:

我正在本地计算机上开发一个带有Flask的web应用程序,它需要访问我的远程Mysql服务器。 我在浏览器上收到以下错误消息:

MySQLdb._exceptions.OperationalError
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'Nino'@'lneuilly-657-1-15-173.w193-248.abo.wanadoo.fr' (using password: YES)")
我的尝试:

我在Plesk仪表板中启用Mysql服务器上的远程访问。 我向我的Mysql用户授予了完全权限。 我在一个python文件上用一个普通的MySQL连接进行了测试,结果成功了。请参阅下面我尝试的代码:

try:    
    import mysql.connector
    mydb = mysql.connector.connect(
                        host="217.1.1.1",
                        port=3306,
                        user="John",
                        passwd="123456",
                        database="wp_fi1lb"
                    )

    mycursor = mydb.cursor()
    print("Mysql connection 1 succesfull")
except ValueError:
    print("Error mysql connection 1")


from flask import Flask, render_template, url_for, flash, redirect
from flask_mysqldb import MySQL
app = Flask(__name__)

try:
    app.config['SECRET_KEY']='secret'
    app.config['MYSQL_HOST']='217.1.1.1'
    app.config['MYSQL_USERNAME']='John'
    app.config['MYSQL_PASSWORD']='123456'
    app.config['MYSQL_DB']='wp_fi1lb'
    app.config['MYSQL_CURSORCLASS']='DictCursor'

    mysql = MySQL(app)
    cursor=mysql.connection.cursor()
    print("Mysql connection 2 succesfull")
except ValueError:
    print("Error mysql connection 2")
并查看输出:

Mysql connection 1 succesful
Traceback (most recent call last):
  File "c:/wamp64/www/dashboard/test.py", line 30, in <module>
    cursor=mysql.connection.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
Mysql connection 1 succesfull
Traceback (most recent call last):
  File "c:/wamp64/www/dashboard/test.py", line 33, in <module>
    cursor = mysql.get_db().cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
输出:

Mysql connection 1 succesful
Traceback (most recent call last):
  File "c:/wamp64/www/dashboard/test.py", line 30, in <module>
    cursor=mysql.connection.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
Mysql connection 1 succesfull
Traceback (most recent call last):
  File "c:/wamp64/www/dashboard/test.py", line 33, in <module>
    cursor = mysql.get_db().cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
Mysql连接1成功
回溯(最近一次呼叫最后一次):
文件“c:/wamp64/www/dashboard/test.py”,第33行,在
cursor=mysql.get_db().cursor()
AttributeError:“非类型”对象没有属性“游标”
正如你所看到的,我们有完全相同的问题

我不知道我做错了什么?
如果我可以连接mysql.connector,为什么我要使用flask mysqldb?

只要检查一下你是否能够远程访问数据库,是否使用相同的凭据,我认为最好使用sqlalchemy,因为它对mysql db和其他oneThanks都很好,谢谢你的帮助,但我确实成功地使用mysql.connector远程访问了相同的凭据(参见输出和源代码中的成功连接1)在案例2中,如文档中所示初始化应用程序