6

I'm putting together a script that has a requirement of knowing libmysqlclient.so.[15|16|18] .so file. It's usually located in /usr/lib/ , /usr/lib64/ or a mysql/ subdirectory of the aforementioned directories.

I have tried a few things. First of all, sometimes the location can be found in a mysql file in /etc/ld.so.conf.d/mysql* , but that has not been the case on many servers.

Another possibility is searching the above directories for those files. I will know which version of MySQL is being used, so I can search for the proper .so file, but unfortunately many people seem to have multiple .so's installed. For example both may exist:

  • /usr/lib/libmysqlclient.so.15

  • /usr/lib64/libmysqlclient.so.15

In this situation, I'm not sure which .so file is being used.

Is there anyway to tell where the proper libmysqlclient.so is installed?

wrangler
  • 3,080
  • 5
  • 24
  • 20

4 Answers4

7

This will give you all of the libmysql files recognized by the linker. The higher on the list has the higher priority and is more likely to be linked against.

/sbin/ldconfig -p | grep mysql | cut -d\> -f2

One caveat though is that since most applications link by doing a gcc -lmysqlclient they will favor a file in the ldconfig listed as libmysqlclient.so rather than .so.15 or whatever. So personally I would assume that the first libmysqlclient.so is the correct one.

Kyle
  • 1,589
  • 9
  • 14
3

Which shared object library is used depends on the user enviroment and binary that is run. If you su - USER to the user that is running the binary and then run the command ldd MYSQLBINARY | grep mysqlclient that will determine which mysqlclient library is going to be used.

By default on most Linux systems, /usr/lib (used for x86 binaries) and /usr/lib64 (used for x86_64 bit binaries).

Btw, running locate libmysqlclient.so to get a list of all the shared objects that are installed system wide (probably won't report .so files installed in user paths though).

Andrew Case
  • 3,489
  • 3
  • 23
  • 39
0

Remember that the so being used might not even be in /usr/lib or /usr/lib64.....sometimes these things reside in or under /usr/local/lib as well depending on how things were compiled.

I'm sure that there is a totally foolproof method of making the determination. One can make some darn good guesses however.

mdpc
  • 11,856
  • 28
  • 53
  • 67
0

If you know the package name why not list the content of the package and grep for it?

In Redhat, something like ...

rpm -ql mysql | grep libmysql
sdot257
  • 3,059
  • 5
  • 30
  • 39