Installing MySQLdb on osx El Capitan for Python
<p>I am trying:</p>

<pre><code>brew install mysql
pip install mysql-python
</code></pre>

<p>I am getting this output:</p>

<pre class="lang-none prettyprint-override"><code>Collecting mysql-python Using cached MySQL-python-1.2.5.zip Installing
collected packages: mysql-python   Running setup.py install for
mysql-python ... error
    Complete output from command /usr/bin/python -u -c "import setuptools,
tokenize;__file__='/private/var/folders/zf/phyv38gx56jddgzfyqnw0t7h0000gp/T/pip-build-vla6Kt/mysql-python/setup.py';exec(compile(getattr(tokenize,
'open', open)(__file__).read().replace('\r\n', '\n'), __file__,
'exec'))" install --record
/var/folders/zf/phyv38gx56jddgzfyqnw0t7h0000gp/T/pip-_xy5Mn-record/install-record.txt
--single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.11-intel-2.7
    copying _mysql_exceptions.py -&gt; build/lib.macosx-10.11-intel-2.7
    creating build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/__init__.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/converters.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/connections.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/cursors.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/release.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    copying MySQLdb/times.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb
    creating build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -&gt; build/lib.macosx-10.11-intel-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.11-intel-2.7
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv
-DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql-connector-c/6.1.6/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
-c _mysql.c -o build/temp.macosx-10.11-intel-2.7/_mysql.o
    _mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                    cmd_argc = PySequence_Size(cmd_args);
                             ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                    groupc = PySequence_Size(groups);
                           ~ ^~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                            int j, n2=PySequence_Size(fun);
                                   ~~ ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:1127:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_real_escape_string(&amp;(self-&gt;connection), out, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_escape_string(out, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1168:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
            size = PyString_GET_SIZE(s);
                 ~ ^~~~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32:
note: expanded from macro 'PyString_GET_SIZE'
    #define PyString_GET_SIZE(op)  Py_SIZE(op)
                                   ^~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56:
note: expanded from macro 'Py_SIZE'
    #define Py_SIZE(ob)             (((PyVarObject*)(ob))-&gt;ob_size)
                                     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    _mysql.c:1178:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_real_escape_string(&amp;(self-&gt;connection), out+1, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1180:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_escape_string(out+1, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1274:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
            if ((n = PyObject_Length(o)) == -1) goto error;
                   ~ ^~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25:
note: expanded from macro 'PyObject_Length'
    #define PyObject_Length PyObject_Size
                            ^
    _mysql.c:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1589:10: warning: comparison of unsigned expression &lt; 0 is always false [-Wtautological-compare]
            if (how &lt; 0 || how &gt;= sizeof(row_converters)) {
                ~~~ ^ ~
    14 warnings generated.
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql-connector-c/6.1.6/include/my_config.h:176:9:
warning: 'SIZEOF_LONG' macro redefined [-Wmacro-redefined]
    #define SIZEOF_LONG      8
            ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:54:17:
note: previous definition is here
    #        define SIZEOF_LONG             4
                    ^
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql-connector-c/6.1.6/include/my_config.h:181:9:
warning: 'SIZEOF_TIME_T' macro redefined [-Wmacro-redefined]
    #define SIZEOF_TIME_T    8
            ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:57:17:
note: previous definition is here
    #        define SIZEOF_TIME_T           4
                    ^
    _mysql.c:1589:10: warning: comparison of unsigned expression &lt; 0 is always false [-Wtautological-compare]
            if (how &lt; 0 || how &gt;= sizeof(row_converters)) {
                ~~~ ^ ~
    3 warnings generated.
    cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.11-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.6/lib -lmysqlclient -o build/lib.macosx-10.11-intel-2.7/_mysql.so
    ld: warning: ignoring file /usr/local/Cellar/mysql-connector-c/6.1.6/lib/libmysqlclient.dylib,
file was built for x86_64 which is not the architecture being linked
(i386):
/usr/local/Cellar/mysql-connector-c/6.1.6/lib/libmysqlclient.dylib
    running install_lib
    copying build/lib.macosx-10.11-intel-2.7/_mysql.so -&gt; /Library/Python/2.7/site-packages
    error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/_mysql.so'

    ---------------------------------------- 
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/zf/phyv38gx56jddgzfyqnw0t7h0000gp/T/pip-build-vla6Kt/mysql-python/setup.py';exec(compile(getattr(tokenize,
'open', open)(__file__).read().replace('\r\n', '\n'), __file__,
'exec'))" install --record
/var/folders/zf/phyv38gx56jddgzfyqnw0t7h0000gp/T/pip-_xy5Mn-record/install-record.txt
--single-version-externally-managed --compile" failed with error code 1 in
/private/var/folders/zf/phyv38gx56jddgzfyqnw0t7h0000gp/T/pip-build-vla6Kt/mysql-python/
</code></pre>

<p>What am I doing wrong and how can I install it?</p>

<p>The relevant error message is this:</p>

<pre class="lang-none prettyprint-override"><code>error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/_mysql.so
</code></pre>

<p>It can't copy to the target directory because of missing permissions.</p>

<p>You can either install it to the local user site directory using</p>

<pre><code>pip install --user mysql-python
</code></pre>

<p>In this case it will only be available to the current user.</p>

<p>Or if you really need to install for all users on the machine, you can use <code>sudo pip install mysql-python</code> to install as root, but that is usually not recommendable.</p>

python osx python-2.7 mysql-python osx-elcapitan