By RamzanAli
File "/usr/local/lib/python3.6/dist-packages/flask_sqlalchemy/__init__.py", line 972, in create_engine, referer: http://123.123.123.123/
[Tue Jul 21 12:09:17.446596 2020] [wsgi:error] [pid 2995] [client 117.96.57.241:57794] return sqlalchemy.create_engine(sa_url, **engine_opts), referer: http://123.123.123.123/
[Tue Jul 21 12:09:17.446600 2020] [wsgi:error] [pid 2995] [client 117.96.57.241:57794] File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine, referer: http://123.123.123.123/
[Tue Jul 21 12:09:17.446606 2020] [wsgi:error] [pid 2995] [client 117.96.57.241:57794] return strategy.create(*args, **kwargs), referer: http://123.123.123.123/
[Tue Jul 21 12:09:17.446609 2020] [wsgi:error] [pid 2995] [client 117.96.57.241:57794] File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/strategies.py", line 87, in create, referer: http://123.123.123.123/dbapi = dialect_cls.dbapi(**dbapi_args), referer: http://123.123.123.123/File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi, referer: http://123.123.123.123/return __import__("MySQLdb"), referer: http://123.123.123.123/
ModuleNotFoundError: No module named 'MySQLdb', referer: http://123.123.123.123/
[Tue Jul 21 12:09:17.446637 2020] [wsgi:error] [pid 2995] [client 117.96.57.241:57794] , referer: http://123.123.123.123/
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
The error message you are seeing: ModuleNotFoundError: No module named ‘MySQLdb’
indicates that the required MySQL driver for Python is not installed in your environment. You need to install the MySQLdb package (also known as mysqlclient) to interact with a MySQL database using SQLAlchemy.
Here are the steps to set up the MySQL connection in a Flask app running on a WSGI production server:
Install MySQL Driver:
Run the following command to install the mysqlclient package:
pip install mysqlclient
Configure Your Flask Application:
In your Flask application, you need to set up the database URI to point to your MySQL database:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://username:password@localhost/dbname'
db = SQLAlchemy(app)
Make sure to replace username, password, localhost, and dbname with your actual database credentials and host information.
Configure WSGI:
mod_wsgi or gunicorn, make sure that it is properly configured to serve your Flask application. You may need to refer to specific documentation depending on the WSGI server you are using.Restart Your WSGI Server:
Check Application Logs:
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.