First, install Flask-MySQLdb:

$ pip install flask-mysqldb

Flask-MySQLdb depends, and will install for you, recent versions of Flask (0.12.4 or later) and mysqlclient. Flask-MySQLdb is compatible with and tested on Python 2.7, 3.5, 3.6 and 3.7.

Next, add a MySQL instance to your code:

from flask import Flask
from flask_mysqldb import MySQL

..from the info provided - here.

link to the documentation - here.

Answer from None on Stack Overflow
Discussions

No module named flaskext.mysql
Hello, I don't understand what I am doing wrong... I pip install and then tried from flaskext.mysql import MySQLor from flask_mysqldb import MySQL but I can't get it working : No module nam... More on github.com
🌐 github.com
9
September 1, 2016
Need help with mysql error.

I see the virtual environment set up in your path. Was this working before outside the virtual environment? Did you move to venv and not have the libraries there? Or, did you switch venvs and it was loaded in the other one?

Just throwing things out there...

More on reddit.com
🌐 r/flask
11
4
May 17, 2018
flask-mysqldb problem : Forums : PythonAnywhere
The specific error you're getting means that you need to install flask_mysqldb into your virtualenv -- just start a bash console inside the virtualenv using the link on the "Web" page, then use pip to install it. However, you won't be able to connect to a remote MySQL server from a free account ... More on pythonanywhere.com
🌐 pythonanywhere.com
No module named flaskext : Forums : PythonAnywhere
It's not a general system problem that we can resolve -- it's a configuration problem for a given site. Is the error you getting the "no module named flaskext" one? I see your website is using a virtualenv -- have you installed the flaskext package? giles | 12916 posts | PythonAnywhere staff | Dec. 13, 2018, 12:01 p.m. | permalink · Don't know if anyone still reads this, but I had the same problem with flask_mysqldb ... More on pythonanywhere.com
🌐 pythonanywhere.com
🌐
Stack Overflow
stackoverflow.com › questions › 68931659 › import-flask-mysqldb-could-not-be-resolved-pylancereportmissingimports
python - Import "flask_mysqldb" could not be resolved Pylance(reportMissingImports) - Stack Overflow
And I don't really know if I'm missing something because when I try to install stuff it says "requirement already fulfilled" and I'm panicking because I don't know what I'm doing wrong. This is the actual code I'm working with but I can't use anything related to databases because the 2nd line doesn't work: from flask import Flask, render_template, request, redirect, url_for, flash
🌐
Python Forum
python-forum.io › thread-24981.html
No module named 'flask_mysqldb'
Dear Phyton's friends, ı'm freaking out last five hours. I use visual studio code and python 3.6 (64bit). I could'not import flask_mysqldb from MySQL. My error code is ' ModuleNotFoundError: No module named 'flask_mysqldb' '. Please help me If I don...
🌐
JustAnswer
justanswer.com › computer-programming › ogpuk-keep-getting-no-module-named-flask-mysqldb.html
How to Fix 'No Module Named flask_mysqldb' Error in Python
I suspect there could be several instances of SQL Server running, and it may be connecting to a different instance. ... Running on http://127.0.0.1:5000 Press CTRL+C to quit * Restarting with stat * Debugger is active! ... The error is related to the database. The error message states: MySQLdb.OperationalError: (1049, "Unknown database 'app'") ... That is the Flask application operating on port 5000; I was referring to the MySQL server.
🌐
GitHub
github.com › admiralobvious › flask-mysqldb › issues › 4
No module named flaskext.mysql · Issue #4 · alexferl/flask-mysqldb
September 1, 2016 - Hello, I don't understand what I am doing wrong... I pip install and then tried from flaskext.mysql import MySQLor from flask_mysqldb import MySQL but I can't get it working : No module nam...
Author   CBaptiste
🌐
Reddit
reddit.com › r/flask › need help with mysql error.
r/flask on Reddit: Need help with mysql error.
May 17, 2018 -

Hi, I have been working on a flask app for a little over a month with no problem, but today I could not run the app due to a mysql error. Specifically the error was:

File "app.py", line 4, in <module>

from flask_mysqldb import MySQL

File "C:\Users\gztau\documents\Atom_Flask\venv\lib\site-packages\flask_mysqldb\__init__.py", line 1, in <module>

import MySQLdb

File "C:\Users\gztau\documents\Atom_Flask\venv\lib\site-packages\MySQLdb\__init__.py", line 19, in <module>

import _mysql

ModuleNotFoundError: No module named '_mysql'

Mysql has been working fine up til now. I have never changed anything in any of the venv, or init files, this is the first time ive even looked at any of it. Any suggestions on what is going on, i am at a loss. Im pretty new to programming, getting better with flask etc, and was just using it last night. Sorry to bother, but thanks for any help.

🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 14704
flask-mysqldb problem : Forums : PythonAnywhere
The specific error you're getting means that you need to install flask_mysqldb into your virtualenv -- just start a bash console inside the virtualenv using the link on the "Web" page, then use pip to install it. However, you won't be able to connect to a remote MySQL server from a free account ...
Find elsewhere
🌐
PyPI
pypi.org › project › Flask-MySQLdb
Flask-MySQLdb · PyPI
Flask-MySQLdb provides MySQL connection for Flask.
      » pip install Flask-MySQLdb
    
Published   Oct 04, 2023
Version   2.0.0
🌐
Columbia University
blogs.cuit.columbia.edu › jp3864 › 2020 › 07 › 01 › installing-flask-mysqldb-debug-and-solution
Installing flask-mysqldb (Debug and Solution) – Jessica's blog
July 1, 2020 - In this post, I will go through how I was able to install flask-mysqldb after going through lots of trial and error.
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 11739
No module named flaskext : Forums : PythonAnywhere
It's not a general system problem that we can resolve -- it's a configuration problem for a given site. Is the error you getting the "no module named flaskext" one? I see your website is using a virtualenv -- have you installed the flaskext package? giles | 12916 posts | PythonAnywhere staff | Dec.
🌐
RoseIndia
roseindia.net › answers › viewqa › pythonquestions › 102579-ModuleNotFoundError-No-module-named-Flask-MySQLdb.html
ModuleNotFoundError: No module named 'Flask-MySQLdb'
After the installation of Flask-MySQLdb python library, ModuleNotFoundError: No module named 'Flask-MySQLdb' error will be solved.
🌐
Reddit
reddit.com › r/sql › first time using mysql..importerror:
r/SQL on Reddit: first time using mysql..ImportError:
April 28, 2019 -

First time using mysql…ImportError:

I have looked all over and tried everything to resolve this issue for a day or two, but haven't had any luck.

I am using flask and sql for the first time(macOS), I have everything installed. But I am guessing that it is either installed incorrectly, or in the wrong folder.

I installed sql directly from their website, I then followed this advice here...

$ open -t .bash_profile  export PATH=${PATH}:/usr/local/mysql/bin/

I know that it does work because I am able to go into the database in my terminal. my Flask app does work (it runs before adding all of the sql code), but the only thing I am having trouble with is running my program after importing(from flask_mysqldb import MySQL).

This is the tutorial I am following as well, https://www.youtube.com/watch?v=6L3HNyXEais

my error is here...

Error: While importing "app", an ImportError was raised:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/cli.py", line 235, in locate_app     __import__(module_name) File "/Users/jonathanmast/flask_prac/app.py", line 2, in <module> from flask_mysqldb import MySQL File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_mysqldb/__init__.py", line 1, in <module> import MySQLdb File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module> from . import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.18.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
🌐
GitHub
github.com › alexferl › flask-mysqldb
GitHub - alexferl/flask-mysqldb: MySQL extension for the Flask web framework · GitHub
Flask-MySQLdb is compatible with and tested with Python 3.8+. ... from flask import Flask from flask_mysqldb import MySQL app = Flask(__name__) # Required app.config["MYSQL_USER"] = "user" app.config["MYSQL_PASSWORD"] = "password" app.config["MYSQL_DB"] = "database" # Extra configs, optional: app.config["MYSQL_CURSORCLASS"] = "DictCursor" app.config["MYSQL_CUSTOM_OPTIONS"] = {"ssl": {"ca": "/path/to/ca-file"}} # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes mysql = MySQL(app) @app.route("/") def users(): cur = mysql.connection.cursor() cur.execute("""SELECT user, host FROM mysql.user""") rv = cur.fetchall() return str(rv) if __name__ == "__main__": app.run(debug=True)
Starred by 128 users
Forked by 61 users
Languages   Python 91.7% | Makefile 8.3%