2

On centos 7.5 I have mysql 5.7.24 installed, with subsequent installation of mysql-devel.

I'm trying to get the MySQLdb module of Python 3.7 working, however, on importing it with (in python)

import MySQLdb

I get the following error

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/lib/python3.7/site-packages/MySQLdb/__init__.py", line 
18, in <module>
import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

I checked for libmysqlclient.so.18 on my server with

locate libmysql

I get the following result

/usr/lib64/mysql/libmysqlclient.a
/usr/lib64/mysql/libmysqlclient.so
/usr/lib64/mysql/libmysqlclient.so.20
/usr/lib64/mysql/libmysqlclient.so.20.3.11
/usr/lib64/mysql/libmysqlservices.a

So apparently libmysqlclient.so.18 is missing. There was a suggestion in this thread to use yum install mariadb-libs but mariadb-libs (saying that .so.18 is there) but that install attempt results in

Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 is obsoleted by mysql- 
community-server-5.7.24-1.el7.x86_64 which is already installed
Nothing to do

Can anyone please suggest a fix on how to handle the missing libmysqlclient.so.18 ?

  • How did you install Python 3.7? And how did you install this MySQLdb module? – Michael Hampton Oct 27 '18 at 14:47
  • @MichaelHampton , I installed Python through Anaconda distribution (the official website), it's in the /opt folder, and MySQLdb via "pip install mysqlclient" where pip is again the one which came with Anaconda package. – Hayk Oct 27 '18 at 18:29
  • Hm. I'm pretty sure Anaconda's mysqlclient was built against the original version of MySQL that came with CentOS, rather than the MySQL 5.7 that you've replaced it with. So, where did your MySQL come from? – Michael Hampton Oct 27 '18 at 18:46
  • @MichaelHampton, MySQL was initially with version 5.6, which I replaced with 5.7.24. Nothing came with CentOS (if you mean it was a default setting), and I installed version MySQL 5.6 myself earlier (from MySQL's official site). With that version of MySQL I then installed mysql-devel via " $ sudo yum install mysql-devel " and then "$ sudo /opt/anaconda3/bin/pip install mysqlclient " . Afterwards, the "import MySQLdb" from python 3.7 was working fine. It became broke after switching to MySQL 5.7, although I did all the above (removed and installed mysqlclient via pip). – Hayk Oct 27 '18 at 18:53
1

Find and install a package that provides libmysqlclient.so.18

$ yum provides */libmysqlclient.so.18
...
1:mariadb-libs-5.5.56-2.el7.i686 : The shared libraries required for 
MariaDB/MySQL clients
Repo        : base
Matched from:
Filename    : /usr/lib/mysql/libmysqlclient.so.18

On your system it may be different.

  • thanks for your reply. I run the command you suggested, and among the packages which had libmysqlcient.so.18 was this one "mysql-community-libs-compat-5.7.24-1.el7.i686" That, however, is already installed, since running "sudo yum install the_package_name" ends up with the message "mysql-community-libs-compat-5.7.24-1.el7.i686 already installed and latest version Nothing to do". Do you have a guess as what might be going on ? – Hayk Oct 27 '18 at 19:00
  • Also, the folder /usr/lib/mysql/ ( the same as in the original question, but with lib instead of lib64) contains libmysqlclient_r.so.18 -> libmysqlclient.so.18 libmysqlclient_r.so.18.1.0 -> libmysqlclient.so.18.1.0 libmysqlclient.so.18 -> libmysqlclient.so.18.1.0 libmysqlclient.so.18.1.0 libmysqlclient.so.20 -> libmysqlclient.so.20.3.11 libmysqlclient.so.20.3.11 I'm not sure if this might be useful though. – Hayk Oct 27 '18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.