Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Can you be more specific about what you're trying to accomplish? –  Andrew Case Nov 1 '11 at 5:44

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer

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).

share|improve this answer

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.

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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