Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import MySQLdb fails with undefined symbol: SSL_get_error #379

Closed
EarthenSky opened this issue Aug 9, 2019 · 9 comments
Closed

import MySQLdb fails with undefined symbol: SSL_get_error #379

EarthenSky opened this issue Aug 9, 2019 · 9 comments

Comments

@EarthenSky
Copy link

EarthenSky commented Aug 9, 2019

Found this error while using django but managed to isolate it to mysqlclient.
After installing mysqlclient using pip it throws the following error:

Python 3.7.4 (default, Jul 10 2019, 21:14:36)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: /usr/local/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-x86_64-linux-gnu.so: undefined symbol: SSL_get_error
>>>

I inspected the file _mysql.cpython-37m-x86_64-linux-gnu.so using nm and it seems to have a lot of undefined symbols. Compilation error?

[user@n]$ nm -u /usr/local/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-x86_64-linux-gnu.so
                 U access@@GLIBC_2.2.5
                 U __assert_fail@@GLIBC_2.2.5
...
                 U SSL_get_current_cipher
                 U SSL_get_error
                 U SSL_get_ex_data
...
                 U X509_STORE_set_flags
                 U X509_verify_cert_error_string

mysqlclient version 1.4.2.post1
Centos 7
Mariadb 10.4.7

@methane
Copy link
Member

methane commented Aug 9, 2019

Undefined symbols are normal. They are provided by dynamically linked libraries.
Try ldd _mysql.cpython-37m-x86_64-linux-gnu.so and mysql_config.

@EarthenSky
Copy link
Author

command output:

[user@n ~]$ ldd /usr/local/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-x86_64-linux-gnu.so
        linux-vdso.so.1 =>  (0x00007ffecc6aa000)
        libpython3.7m.so.1.0 => /usr/local/lib/libpython3.7m.so.1.0 (0x00007fbb6ab4b000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbb6a92f000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fbb6a562000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fbb6a32b000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fbb6a127000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fbb69f24000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fbb69c22000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fbb6b310000)
        libfreebl3.so => /lib64/libfreebl3.so (0x00007fbb69a1f000)
[user@n ~]$ mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/include/mysql -I/usr/include/mysql/mysql]
        --include        [-I/usr/include/mysql -I/usr/include/mysql/mysql]
        --libs           [-L/usr/lib64/ -lmariadb]
        --libs_r         [-L/usr/lib64/ -lmariadb]
        --plugindir      [/usr/lib64/mysql/plugin]
        --socket         [/var/lib/mysql/mysql.sock]
        --port           [3306]
        --version        [10.4.7]
        --libmysqld-libs [-L/usr/lib64  -lmysqld -lpthread -lz -lm -ldl -lssl -lcrypto -lcrypt -llzma -laio -lsystemd]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/include/mysql]
                pkglibdir     [/usr/lib64]
                plugindir     [/usr/lib64/mysql/plugin]

@methane
Copy link
Member

methane commented Aug 9, 2019

  • Uninstall mysqlclient
  • Remove pip cache
  • Install mysqlclient again with logs (pip install mysqlclient --log pip_install_mysqlclient.txt).
  • Paste the log to gist.

@EarthenSky
Copy link
Author

Assuming removing the pip cache is the option --no-cache-dir
Ran the following command:

sudo python -m pip install mysqlclient --no-cache-dir --log pip_install_mysqlclient.txt

Gist Link: https://gist.github.com/EarthenSky/464e6a309c058935e1e97d1890eb3db2

@methane
Copy link
Member

methane commented Aug 9, 2019

You still can not import _mysql?

mysqlclient doesn't link ssl, but libmaria.a does. You need to install OpenSSL libraries.
(I don't know yum package name, I'm not CentOS user).

@EarthenSky
Copy link
Author

Yes, I still can't import _mysql
OpenSSL libraries are already installed, I suspect it is more of an error with mariadb.

Thanks for your help.

@EarthenSky
Copy link
Author

Managed to fix the error, it was with with mariadb.

Originally I foolishly followed this advice which fixes the install error I had:
r-dbi/RMySQL#197
But it causes mysqlclient to compile using the wrong libmariadb.

To fix my error I undid the previous change I had made, then followed the following response to install mysql-devel instead of mariadb-devel:
https://stackoverflow.com/questions/46495448/unable-to-install-mysqlclient-on-centos

Closing this.

@ottok
Copy link

ottok commented Oct 28, 2020

If you are running Ubuntu/Debian, the correct solution is to install libmariadb-dev-compat and rebuild (with MariaDB 10.3+).

@grooverdan
Copy link

grooverdan commented Oct 31, 2020

@methane removed ssl libraries in #409.

mysql-8.0.22 (tarball) still includes ssl in mysql_config --libs:

$ find mysq* -name mysql_config -print  -exec {} --libs \; 
mysql-5.6.49/bin/mysql_config
-L/usr/local/mysql-5.6.49/lib -lmysqlclient -lpthread -lm -lrt -ldl
mysql-5.7.31/bin/mysql_config
-L/usr/local/mysql-5.7.31/lib -lmysqlclient -lpthread -lm -lrt -ldl
mysql-8.0.21/bin/mysql_config
-L/usr/local/mysql-8.0.21/lib -Wl,-R,/usr/local/mysql-8.0.21/lib -L/usr/local/mysql-8.0.21/lib/private -Wl,-R,/usr/local/mysql-8.0.21/lib/private -lmysqlclient -lpthread -lm -lrt -lcrypto -lssl -ldl
mysql-8.0.22-linux-glibc2.12-x86_64/bin/mysql_config
-L/usr/local/mysql-8.0.22-linux-glibc2.12-x86_64/lib -Wl,-R,/usr/local/mysql-8.0.22-linux-glibc2.12-x86_64/lib -L/usr/local/mysql-8.0.22-linux-glibc2.12-x86_64/lib/private -Wl,-R,/usr/local/mysql-8.0.22-linux-glibc2.12-x86_64/lib/private -lmysqlclient -lpthread -lm -lrt -lcrypto -lssl -ldl -lresolv

mariadb connector -c added (early 2016, expand mariadb_config/mariadb_config.c.in in link) --libs_sys. This isn't an option in mysql's connector c.

Is libraries.append(mysql_config("libs_sys")) acceptable after the ssl/crypto/z removal?

Alternately using pkg-config --libs and pkg-config --libs --static seems to report the right libraries on all supported mysql and mariadb versions:

$ find /usr/local/mysql-* -name \*pc -print -printf "libs:\n" -exec pkg-config --libs {} \; -printf "\nAnd --libs --static:\n" -exec pkg-config --libs --static {} \;
/usr/local/mysql-5.7.31/lib/pkgconfig/mysqlclient.pc
libs:
-L/usr/local/mysql/lib -lmysqlclient 

And --libs --static:
-L/usr/local/mysql/lib -lmysqlclient -lpthread -lm -lrt -ldl 
/usr/local/mysql-8.0.21/lib/pkgconfig/mysqlclient.pc
libs:
-L/usr/local/mysql/lib -Wl,-R,/usr/local/mysql/lib -L/usr/local/mysql/lib/private -Wl,-R,/usr/local/mysql/lib/private -lmysqlclient 

And --libs --static:
-L/usr/local/mysql/lib -Wl,-R,/usr/local/mysql/lib -L/usr/local/mysql/lib/private -Wl,-R,/usr/local/mysql/lib/private -lmysqlclient -lpthread -lm -lrt -lcrypto -lssl -ldl 
/usr/local/mysql-8.0.22-linux-glibc2.12-x86_64/lib/pkgconfig/mysqlclient.pc
libs:
-L/usr/local/mysql/lib -Wl,-R,/usr/local/mysql/lib -L/usr/local/mysql/lib/private -Wl,-R,/usr/local/mysql/lib/private -lmysqlclient 

And --libs --static:
-L/usr/local/mysql/lib -Wl,-R,/usr/local/mysql/lib -L/usr/local/mysql/lib/private -Wl,-R,/usr/local/mysql/lib/private -lmysqlclient -lpthread -lm -lrt -lcrypto -lssl -ldl -lresolv


$ pkg-config --libs --static ./mariadb_config/libmariadb.pc
-L/usr/local/lib/mariadb/ -lmariadb -ldl -lm -lpthread -lssl -lcrypto 

$ pkg-config --libs  ./mariadb_config/libmariadb.pc
-L/usr/local/lib/mariadb/ -lmariadb 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants