1

I'm new to Django, and trying to setup a basic web-app connecting to MySQL on macOS. However, I can't seem to get mysqlclient to work on macOS.

I'm running a virtual environment and the following versions:

$ brew --version
Homebrew 1.8.5
$ pip --version
pip 18.1
$ python --version
Python 3.7.1
$ mysql --version
mysql  Ver 8.0.12 for osx10.14 on x86_64 (Homebrew)

When I try pip install mysqlclient (https://pypi.org/project/mysqlclient/) I get

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

According to the documentation "You may need to install the Python and MySQL development headers and libraries like so:" $ brew install mysql-connector-c This gives another error:

Error: Cannot install mysql-connector-c because conflicting formulae are installed.
  mysql: because both install MySQL client libraries

Please `brew unlink mysql` before continuing.
$ brew unlink mysql
$ brew install mysql-connector-c 
==> Pouring mysql-connector-c-6.1.11.mojave.bottle.tar.gz
  /usr/local/Cellar/mysql-connector-c/6.1.11: 79 files, 15.3MB
brew link mysql
Error: Could not symlink bin/my_print_defaults
Target /usr/local/bin/my_print_defaults
is a symlink belonging to mysql-connector-c
$ brew link --overwrite mysql

Now I can start mysql from console, but when I update django, mysite settings.py to connect to MySQL I get

ModuleNotFoundError: No module named 'MySQLdb'

Here's the relevant settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'django',
        'USER': 'root',
        'PASSWORD': 'XXXXXX',
        'HOST': 'localhost', 
        'PORT': '3306',
    }
}

I've also checked mysql_config as per the bug report https://bugs.mysql.com/bug.php?id=86971

Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: Clang 10.0.0.10001145
Options:
        --cflags         [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
        --cxxflags       [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
        --include        [-I/usr/local/Cellar/mysql/8.0.12/include/mysql]
        --libs           [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
        --libs_r         [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
        --plugindir      [/usr/local/Cellar/mysql/8.0.12/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [8.0.12]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/local/Cellar/mysql/8.0.12/include/mysql]
                pkglibdir     [/usr/local/Cellar/mysql/8.0.12/lib]
                plugindir     [/usr/local/Cellar/mysql/8.0.12/lib/plugin]

I've tried a number of different solutions but no luck so far. Feel like I'm going down a rabbit hole - would greatly appreciate any assistance ;)

I've looked at suggested solutions on the following pages but with no resolution yet:

I suspect the issue is due to issues described in simultaneous MySQL Server and Connector/C installations... https://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-installations.html but not sure what to do about it.

Ultradoxx
  • 668
  • 7
  • 14

1 Answers1

4

ld: library not found for -lssl -> missing openssl package, preferably the openssl development package.

From this github issue

brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
danblack
  • 12,130
  • 2
  • 22
  • 41
  • Found suggestions to solve -lssl library not found at https://github.com/brianmario/mysql2/issues/795 tried `brew install openssl` but get `openssl 1.0.2q is already installed and up-to-date` tried `brew install openssl@1.1 ` successfully installs but `pip install mysqlclient` still fails with same error `library not found for -lssl` – Ultradoxx Dec 13 '18 at 06:22
  • 1
    Ah I just had to run `export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/` and get `Successfully installed mysqlclient-1.3.14` – Ultradoxx Dec 13 '18 at 06:28