You need to download the source to MySQL 5.1.x, it’s the tar file called mysql-5.1.xx.tar.gz (xx is version number), unpack it and open a Terminal session where you cd into the source directory and execute the following commands.

./configure -prefix=/usr/local/mysql \
 -with-server-suffix=-standard \
 -enable-thread-safe-client \
 -enable-local-infile \
 -enable-shared \
 -with-zlib-dir=bundled \
 -with-big-tables \
 -with-readline \
 -with-plugins=all \
 -without-docs

If that went without errors you are ready to compile:

make

And if that went also without errors you are ready to install:

sudo make install

And now you’ve got a proper MySQL installation with shared libraries. Which means you can compile and install all kinds of software that requires access to MySQL databases.

Next step: Securing your MySQL install