Cannot connect to mysql database ubuntu 20.4 (VPS) "ModuleNotFoundError: No module named 'MySQLdb'"
I am working on the setup of my first unmanaged vps(ubuntu 20.4) and following the document to connect my django site to mysql server "https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database"
able to setup
- python/django/virtualenv
- mysql server - tested from mysql workbench on my local machine-Ok
- apache2 working ok. able to see the welcome screen with sqlite3.
now moving to mysql. i tried both the way('ENGINE': 'django.db.backends.mysql' and option file '/etc/mysql/my.cnf' to connect to mysql server from django project.
None of the alternatives working. activated virtualenv, installed mysqldb using
a) sudo apt install libmysqlclient-dev default-libmysqlclient-dev b) pip install wheel c) pip install mysqlclient
while trying to migrate following error encountered. tried with all the option available on stakoverflow, i found none of them working.
Error: " (envFusion) worker@server:~/fusion/fusionerp$ python manage.py makemigrations Traceback (most recent call last): File "/home/worker/fusion/envFusion/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 15, in import MySQLdb as Database ModuleNotFoundError: No module named 'MySQLdb' The above exception was the direct cause of the following exception: . . File "/home/worker/fusion/envFusion/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 17, in raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? "
with ubuntu 20.04 deafult python version is 3.8 and connecting to mysql with 3.8 is a bit challenge so you need to downgrade python to 3.6 or downgrade to ubuntu 18 if you are starting a fresh.
Found a tutorial to downgrade using alternatives and it worked. But had my other dependencies where i need python >= 3.7. So i had no other choice but refresh my ubuntu 20.04 on vps and configured with postgres. it is working way better than i expected with apache2/restframework/redis.
