Django 2.2 error - mysql connection

Asked

Viewed 485 times

1

Hello! Here’s the thing, I’m having a problem connecting to mysql with Django. The error is this:

Django.core.exceptions.Improperlyconfigured: Error loading Mysqldb module. Did you install mysqlclient?

The first solution I found on the internet was to simply install this module with Pip install mysqlclient. Without success, I was returned a giant mistake.

running build_ext building 'Mysqldb. _mysql' Extension error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

I tried to install "Microsoft Visual C++ Build Tools", unsuccessful.

The second solution I found was to add the following lines inside the file Settings.py, soon after installing pymysql with Pip.

 import pymysql

 pymysql.install_as_MySQLdb()

This returned me the following error:

Django.core.exceptions.Improperlyconfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

I have no idea what it can be or what to do, since I’m a beginner and I don’t have much sense :/

Does anyone have any idea what it might be? Thank you and await reply!

  • You can run everything with Docker, if you are willing I can show a working setup. This error there has face of being problem with the version of you and the SO, the last message there says that you are with an old version of mysqlclient, tries to put the younger one

1 answer

2


Seems to be a problem of divergence with the required Mysql versions and the version installed on the machine.

First step upgrade python to the latest version.

Upgraded and before installing the package Mysqlclient. On the Mysqlclient page the manufacturer informs that there are installation prerequisites for the package for each operating system. What you should do is install the Mysqlclient development libraries...

If the environment is Linux:

sudo apt-get install python-dev default-libmysqlclient-dev # Debian / Ubuntu

sudo yum install python-devel mysql-devel # Red Hat / CentOS

If the environment is Mac-OS:

brew install mysql-connector-c 

If the environment is Windows follow the steps...

Install the Wheeler:

pip install wheel

Then download the necessary Wheels on http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python. For example in Windows 10 64bits I downloaded the file mysqlclient‑1.4.2‑cp38‑cp38m‑win_amd64.whl

After download install the Wheels:

pip install mysqlclient‑1.4.2‑cp38‑cp38m‑win_amd64.whl

In windows will still have to install the Runtime of the MSVC


Completed these step install Mysqlclient on the system.

pip install --only-binary :all: mysqlclient
  • To make this work remember to have Mysql installed on the system. Preferably updated.

  • I followed these steps. I am in a 64bit Windows 10 environment. When I went to install the file . whl, I got the following error: "ERROR: mysqlclient-1.4.2-cp37-cp37m-win_amd64.whl is not a supported wheel on this Platform."

  • Try another version mysqlclient-1.4.2-cp36-cp36m-win_amd64.whl or more antga

  • I tried them all, and it still didn’t work... :/

  • 1

    The answer is marked "accepted" - if it hasn’t worked yet, clear , and it may be that the author of the above answer, or someone else will help you. Maracada as accepted, everyone will think it’s already been solved and move on.

  • The merit here is to solve the problem and not simply give an answer. If the problem persists, weaning the answer and let’s go to another alternative.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.