6

I'm going to build a docker image by the following Dockerfile:

FROM python:2.7-alpine
RUN set -ex \
        && apk --no-cache add --virtual build-dependencies \
        && pip install --no-cache-dir mysql-python

It downloads the package via:

Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)

and executes

python setup.py install

but it failes and returns the following error:

_mysql.c: In function '_mysql_ConnectionObject_ping':
_mysql.c:2005:41: error: 'MYSQL {aka struct st_mysql}' has no member named 'reconnect'
  if ( reconnect != -1 ) self->connection.reconnect = reconnect;
                                         ^
error: command 'gcc' failed with exit status 1

but when I try with:

FROM python:2.7

it prefectly works. any idea?

2 Answers 2

4

Solution is to use mysqlclient package instead of MySQL-python, it's a fork that solves multiple issues current MySQL-python has.

https://github.com/PyMySQL/mysqlclient-python

Sign up to request clarification or add additional context in comments.

1 Comment

This looks like the best answer. The fork is updated. The old library (which we've used) hasn't been released since 2014 - which may means it's pretty dead.
0

My understanding from this comment is that mysql and mariadb have a slightly different API and that this causes the compilation to fail in alpine.

Alpine already provides the py-mysqldb package that works fine, but it depends on its own python2 package. My recommendation is to use something like:

FROM alpine:3.8

RUN apk --no-cache add python2 py-mysqldb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.