I have a web server running Rocky Linux 9.4 with Virtualmin on it. WIthin Virtualmin, there is a script that will configure Django to install and set up a project for a website. The Django version is 5.0.6, with a requirement of Python 3.10 or newer. I was able to install Python 3.12 on the server without issue, and configure the links so that the default version is now 3.12 - So far, so good.
Where I am running into trouble is getting Python 3.12 to talk to mySQL on my server. When I run the install script, it installs the python3-mysqlclient module, but then when it tries to connect, it can’t establish the connection to the database. I suspect everything is installed, but I need to configure something to get Python to talk to mySQL, and I’m at a loss how to make that happen. I’ve worked with Virtualmin support, but hit the limits of what they can handle - the script works on other Distros that use Python 3.10 or later as default. How do I tell Python to work with mySQL?
Output from the script is below:
Python module MySQLdb is required ..
Installing package python3-mysqlclient ..
Installing package(s) with command /bin/dnf -y update python3-mysqlclient ..
Last metadata expiration check: 0:23:22 ago on Thu Jun 20 11:55:07 2024.
Dependencies resolved.
Nothing to do.
Complete!
.. install complete.
.. done
Now installing Django version 5.0.6 ..
DB initialization install failed :
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/krdb/domains/experimental.krdb.net/.local/Experimental/manage.py", line 22, in <module>
main()
File "/home/krdb/domains/experimental.krdb.net/.local/Experimental/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.12/site-packages/django/core/management/__init__.py", line 416, in execute
django.setup()
File "/usr/local/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.12/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/usr/local/lib/python3.12/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 994, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/usr/local/lib/python3.12/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 59, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.12/site-packages/django/db/models/base.py", line 143, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "/usr/local/lib/python3.12/site-packages/django/db/models/base.py", line 371, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.12/site-packages/django/db/models/options.py", line 243, in contribute_to_class
self.db_table, connection.ops.max_name_length()
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/db/utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 18, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Installation can be continued manually at https://experimental.krdb.net//
More information on using this script can be found at http://www.djangoproject.com/
.. installation was only partially complete.