Setting up Mysql++ in linux - mysql

I want to connect to a mysql database with C++ in linux. On my local machine I am running Ubuntu, and installed the mysql server and client packages:
sudo apt-get install mysql-server mysql-client
I came across Mysql++ but have some problems when running ./configure from their binary package. The error says:
checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'
I see where I can use this command to specify the path:
./configure --with-mysql-lib=/...
but I do not know where to point it to. I used whereis mysql but cannot find any mysql directory that contains a lib subdirectory. Where would the mysqlclient libraries be installed?
EDIT:
After doing locate libmysqlclient I got back
/usr/lib/i386-linux-gnu/libmysqlclient.so.18
/usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.0.0
/usr/share/doc/libmysqlclient18
/usr/share/doc/libmysqlclient18/changelog.Debian.gz
/usr/share/doc/libmysqlclient18/copyright
/var/cache/apt/archives/libmysqlclient18_5.5.22-0ubuntu1_i386.deb
/var/lib/dpkg/info/libmysqlclient18:i386.list
/var/lib/dpkg/info/libmysqlclient18:i386.md5sums
/var/lib/dpkg/info/libmysqlclient18:i386.postinst
/var/lib/dpkg/info/libmysqlclient18:i386.postrm
/var/lib/dpkg/info/libmysqlclient18:i386.shlibs
So, I tried ./configure --with-mysql-lib=/usr/lib/i386-linux-gnu and it seems to complete without any complaining.
Although this solves the problem of getting ./configure to complete, I still have further troubles. When I run make things go fine until this point:
In file included from ./lib/sql_buffer.h:31:0,
from ./lib/sql_buffer.cpp:26: ./lib/refcounted.h:258:2: error: ‘size_t’ does not name a type
./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer()’: ./lib/refcounted.h:89:2: error:
class ‘mysqlpp::RefCountedPointer’ does not have any
field named ‘refs_’ ./lib/refcounted.h: In constructor
‘mysqlpp::RefCountedPointer::RefCountedPointer(T*)’:
./lib/refcounted.h:100:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’
./lib/refcounted.h:104:4: error: ‘refs_’ was not declared in this
scope ./lib/refcounted.h:104:16: error: expected type-specifier before
‘size_t’ ./lib/refcounted.h:104:16: error: expected ‘;’ before
‘size_t’ ./lib/refcounted.h: In constructor
‘mysqlpp::RefCountedPointer::RefCountedPointer(const
ThisType&)’: ./lib/refcounted.h:112:2: error: class
‘mysqlpp::RefCountedPointer’ does not have any field
named ‘refs_’ ./lib/refcounted.h:115:8: error: ‘refs_’ was not
declared in this scope ./lib/refcounted.h: In destructor
‘mysqlpp::RefCountedPointer::~RefCountedPointer()’:
./lib/refcounted.h:125:7: error: ‘refs_’ was not declared in this
scope ./lib/refcounted.h: In member function ‘void
mysqlpp::RefCountedPointer::swap(mysqlpp::RefCountedPointer::ThisType&)’: ./lib/refcounted.h:246:13: error: ‘refs_’ was
not declared in this scope make: *** [mysqlpp_sql_buffer.o] Error 1
I'm not really familiar with C++, so I'm not sure what the error means exactly. Any help or direction on how to get Mysql++ setup from this point would be much appreciated. Although, I admit that I'm also starting to look for alternative libraries to use.

this problem is caused because size_t depends on the inclusion of stddef namespace before it is called in the configuration (make) files.
i had the very same problem (using an amazon EC2 ubuntu 12.04 cloud server) and solved it by editing the offending file (sql_buffer.cpp located, in my case, /home/ubuntu/mysql++-3.1.0/lib) and including stddef (while also moving string namespace up):
#include <stddef.h>
#include <string.h>
#include "sql_buffer.h"
your question is answered with this correction. BUT, you might have additional problems, like i did. so i explain how i solved some subsequent problems, which you might or might not have also.
you might have to use
sudo chown username sql_buffer.cpp
to be able to edit the file, depending on how your install is setup (i am user ubuntu, for example).
i then bumped into another problem:
./ssx/genv2.cpp: In function âbool generate_ssqls2(const char*, const ParseV2*)â:
./ssx/genv2.cpp:70:28: error: âstrcmpâ was not declared in this scope
so i edited the offending file (genv2.cpp) and included string namespace
#include <string.h>
then i had ANOTHER problem with:
./libmysqlpp_ssqls2parse.a(ssqls2parse_parsev2.o): In function `Type':
/home/ubuntu/mysql++-3.1.0/./ssx/parsev2.cpp:256: undefined reference to `mysqlpp::internal::str_to_lwr
i could have edited Makefile.in but chose to simply run in command line:
sudo g++ -o test_ssqls2 test_ssqls2_ssqls2.o -lmysqlpp_ssqls2parse -L. -lmysqlclient -L/usr/lib/x86_64-linux-gnu -lmysqlpp
i then continued the make process.
that worked for me: mysql++ installed and running.

You need to install the header (dev) files, I assume one of these:
apt-cache search mysql
...
libmysqlclient-dev - MySQL database development files
libmysqlclient16 - MySQL database client library
libmysql++-dev - MySQL C++ library bindings (development)
libmysqlcppconn-dev - MySQL Connector for C++ (development files)
...
--with-mysql-lib should not be necessary because the files will be installed in the default locations.

Related

C code using gcc cannot link to mysql header?

I'd like to build on this post, because my symptoms are identical, but the solution seems to be something else.
I am working in a Ubuntu container (Ubuntu 16.04.3 LTS), trying to compile a toy C program that will eventually connect to an SQL server. First things first: I have the latest libmysqlclient-dev installed:
root#1234:/home# apt install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libmysqlclient-dev is already the newest version (5.7.24-0ubuntu0.16.04.1).
0 upgraded, 0 newly installed, 0 to remove and 88 not upgraded.
root#1234:/home#
And when I look in the /usr/include/mysql directory, I see the critical header file I'll need:
root#1234:/home# ls -l /usr/include/mysql | grep mysql.h
-rw-r--r-- 1 root root 29207 Oct 4 05:48 /usr/include/mysql/mysql.h
root#1234:/home#
So far, so good. Now I found this little toy program from here:
#include <stdio.h>
#include "/usr/include/mysql/mysql.h"
int main() {
MYSQL mysql;
if(mysql_init(&mysql)==NULL) {
printf("\nInitialization error\n");
return 0;
}
mysql_real_connect(&mysql,"localhost","user","pass","dbname",0,NULL,0);
printf("Client version: %s",mysql_get_client_info());
printf("\nServer version: %s",mysql_get_server_info(&mysql));
mysql_close(&mysql);
return 1;
}
Now, following the advice of the previous post, I compile using the "-I" option to point to the mysql.h header file. (Yes, I am required to use GCC here):
root#1234:/home# gcc -I/usr/include/mysql sqlToy.c
/tmp/cc8c5JmT.o: In function `main':
sqlToy.c:(.text+0x25): undefined reference to `mysql_init'
sqlToy.c:(.text+0x69): undefined reference to `mysql_real_connect'
sqlToy.c:(.text+0x72): undefined reference to `mysql_get_client_info'
sqlToy.c:(.text+0x93): undefined reference to `mysql_get_server_info'
sqlToy.c:(.text+0xb4): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status
root#1234:/home#
Belly flop! The compiler has no idea what all the mySQL functions are, even though I've done all I can think of to point to that header file. As a sanity check, I made sure those mySQL functions are indeed in that header file; here's one as an example:
root#1234:/home# more /usr/include/mysql/mysql.h | grep mysql_init
libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
MYSQL * STDCALL mysql_init(MYSQL *mysql);
root#1234:/home#
So while I've pointed the compiler to the mysql.h header file in both my code AND with the "-I" option, it still has no clue what those 'mysql' functions are. The "-I" option was the solution in the previous post, but is not working for me here.
So... What might be the problem? I'm assuming this isn't a compiling problem, but maybe a linking one? In other words, I'm showing GCC where the mysql.h file is, but he is still not using it when processing the code?
Headers are not libraries. You are including the MySQL header during compilation, so these functions are defined, but you are not linking against the library which actually provides those functions.
These functions are provided by the libmysqlclient library, so you need to add the -lmysqlclient flag to your command line to fix this. (Note that this is a lower-case l, not an I.)
Additionally, since you are adding /usr/include/mysql to your system header path, you can include the library as
#include <mysql.h>
You do not need to -- and should not! -- specify the full path to the library in the #include directive.

CUDA 7.0 Error while compiling samples

I'm trying to install CUDA 7.0 on Ubuntu 14.04. I've followed the installation instructions as outlined here. Specifically, I've followed steps in section 3.6 and Chapter 6. While compiling the examples (Section 6.2.2.2) using make, I'm getting the following error:
make[1]: Entering directory `/usr/local/cuda-7.0/samples/3_Imaging/cudaDecodeGL'
/usr/local/cuda-7.0/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_20,
code=compute_20 -o cudaDecodeGL FrameQueue.o ImageGL.o VideoDecoder.o
VideoParser.o VideoSource.o cudaModuleMgr.o cudaProcessFrame.o
videoDecodeGL.o -L../../common/lib/linux/x86_64 -L/usr/lib/"nvidia-346"
-lGL -lGLU -lX11 -lXi -lXmu -lglut -lGLEW -lcuda -lcudart -lnvcuvid
/usr/bin/ld: cannot find -lnvcuvid
collect2: error: ld returned 1 exit status
make[1]: *** [cudaDecodeGL] Error 1
make[1]: Leaving directory `/usr/local/cuda-7.0/samples/3_Imaging/cudaDecodeGL'
make: *** [3_Imaging/cudaDecodeGL/Makefile.ph_build] Error 2
If you notice, there is -L/usr/lib/"nvidia-346". In my case, I have installed nvidia-349. What worked for me is to edit NVIDIA_CUDA-7.0_Samples/3_Imaging/cudaDecodeGL/findgllib.mk and change UBUNTU_PKG_NAME = "nvidia-346" to nvidia-349.
In order to properly install CUDA 7.0 on Ubuntu 14.04, you need a nvidia driver version 346 or higher.
If you're using the .deb installation method, the nvidia graphics driver is installed automatically.
If you used the .run file installation method and chose not to install the nvidia driver, you can manually install the driver afterwards through the package manager:
sudo apt-add-repository ppa:xorg-edgers/ppa && sudo apt-get update
sudo apt-get install nvidia-346 nvidia-346-dev nvidia-346-uvm libcuda1-346 nvidia-libopencl1-346 nvidia-icd-346
In my case, I installed nvidia-352 afterwards due to a bug in nvidia-346 and I stumbled upon the same error.
andoum's approach of manually changing the hard-coded UBUNTU_PKG_NAME = "nvidia-346" to UBUNTU_PKG_NAME = "nvidia-352" in NVIDIA_CUDA-7.0_Samples/3_Imaging/cudaDecodeGL/findgllib.mk worked fine for me.
I met the same issue and solution is that put path of nvidia into system path:
sudo gedit /etc/environment
add these path into environment
LIBRARY_PATH=/usr/lib/your_nvidia_edition:$LIBRARY_PATH
In fact I have encountered this problem when I made a make. I installed Cuda 8.0 under my Ubuntu 16.04. This problem had been confusing me for several weeks and I was almost tending to reinstall ubuntu for that after reviewing many suggestions via google, but finally I addressed it myself recently.
First of all, you should replace all the UBUNTU_PKG_NAME= ##nvidia-3xx## to the one of your actually installed nvidia driver version as recommended above. Then you will probably get compiling error after you do a new make. In my case, I have the link errors like
/usr/bin/ld: warning: libGLX.so.0, needed by /usr/lib/nvidia-
375/libGL.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libGLdispatch.so.0, needed by /usr/lib/nvidia-
375/libGL.so, not found (try using -rpath or -rpath-link)
....
or whatever contains missing link errors. Do locate the files you miss like
$ locate libGLX.so.
/usr/lib/nvidia-375/libGLX.so.0
/usr/lib32/nvidia-375/libGLX.so.0
$ locate libGLdispatch.so.0
/usr/lib/nvidia-375/libGLdispatch.so.0
/usr/lib32/nvidia-375/libGLdispatch.so.0
The error above is probably caused the compiling files cannot find in the default cuda libraries as you set, so you just need to copy the missing files to /usr/lib/nvidia-3xx/ (the actual path in your case) and this should work(it works in my case), if it doesn't maybe you could try to link the new add files to the one that need using a
$ sudo ln -s (requested file) (requesting file).
Hope this will help.

Connect to mysql from node.js app, error: "dyld: lazy symbol binding failed: Symbol not found: _mysql_init"

I use OSX 10.6.8 and MySQL from XAMPP.
When I run this node.js app (app.js):
var mysql = require('mysql-libmysqlclient');
var conn = mysql.createConnectionSync();
conn.connectSync('127.0.0.1', 'root', '', 'database_name');
I see this output:
Airs0urce:nodejs airs0urce$ node app.js
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Applications/XAMPP/xamppfiles/htdocs/myproject/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
Expected in: dynamic lookup
dyld: Symbol not found: _mysql_init
Referenced from: /Applications/XAMPP/xamppfiles/htdocs/myproject/nodejs/node_modules/mysql-libmysqlclient/build/Release/mysql_bindings.node
Expected in: dynamic lookup
Trace/BPT trap
Already tried couple solutions after googling.
Added mysql libs from XAMPP directory to include path this way:
export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib/mysql:$DYLD_LIBRARY_PATH
tried to install mysql5-devel using MacPorts, but no luck, building failed:
Airs0urce:~ airs0urce$ sudo port install mysql5-devel
---> Computing dependencies for mysql5-devel
---> Building mysql5-devel
Error: Target org.macports.build returned: shell command failed (see log for details)
Log for mysql5-devel is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_mysql5-devel/mysql5-devel/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>
There is log file if you want to see: http://dl.dropbox.com/u/1875424/main.log
This is because of a config issue on Mac OS X Lion (10.7): lib/libmysqlclient.18.dylib (mysql 5.5 and above).
Step 1:
Make sure you set the path in ~/.profile
export ARCHFLAGS=-arch x86_64
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
Step 2:
I am using rvm so, I used the following command:
rvmsudo ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-opt-lib=/usr/local/mysql/lib
which has solved the issues with rails application on Mac lion and mysql x86_64.
I futzed around with this for a ton of time including setting the DVLD library path and copying the library into /usr/lib.
sudo cp /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib
Heck, anything to get it working. Finally I tried clearing the default for 64 vs 32 bit and it worked!
defaults delete com.apple.versioner.perl
Not sure if my perl is 64 or 32 bit, but my db is 64 bit and just using the default default seems to work better ;-)

Why rasqal configuration can't recognize the already raptor library on cygwin?

I am trying to install rasqal 0.9.20 library http://librdf.org/rasqal/ onto a windows 7 machine with cygwin.Earlier i have successfully installed the raptor-2.2.0 library http://librdf.org/raptor/ and i can verify this with the rapper tool was created after the installation(./configure , ./make ,/make install)
The error that i am getting from the configuration of rasqal is :
./configure --enable-raptor2
...
checking for raptor... configure: error: Raptor2 is not installed - see http://librdf.org/raptor/ to get a version newer than 1.9.0
I can't find a way to fix it. The code from the cofigure file that handles this flag is the below :
11840 # raptor is REQUIRED despite the checking here
11841 RAPTOR_MIN_VERSION=1.4.19
11842 RAPTOR_MAX_VERSION=1.8.99
11843 RAPTOR2_MIN_VERSION=1.9.0
11844
11845 raptor2=no
11846 # Check whether --enable-raptor2 was given.
11847 if test "${enable_raptor2+set}" = set; then :
11848 enableval=$enable_raptor2; raptor2="$enableval"
11849 else
11850 raptor2="no"
11851 fi
Raptor 2.0.0 uses only pkg-config to provide configuration information, raptor-config was removed. The same applies to rasqal itself, the rasqal-config program will go away at some point. The --enable-raptor2 option to rasqal and librdf was for testing the beta raptor2, and it has been removed from rasqal 0.9.22 and librdf GIT head.
Set PKG_CONFIG_PATH to include the correct path:
env PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure
Another method, if available on your system, is to define the environment variable in /etc/environment:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Installation error for DBD::MySQL on OSX v10.6.6

I'm attempting to get DBD::MySQL working on Snow Leopard (v10.6.6). The default version of Perl that comes with the OS is v5.10.0. Since I've read that's 64-bit, I went ahead and downloaded and installed a 64-bit version of MySQL (mysql-5.5.8-osx10.6-x86_64).
Installing and setting up MySQL went smoothly, here's my config and version number for reference.
I used CPAN to download DBI and the DBD::MySQL drivers. I then:
Installed DBI
Setup a Makefile.PL
Ran the make command from the command line
The Makefile.PL said it would use the following settings for compiling and testing:
I will use the following settings for compiling and testing:
cflags (mysql_config ) = -I/usr/local/mysql/include -Os -g -fno-common -fno-strict-aliasing -arch x86_64
embedded (mysql_config ) =
libs (mysql_config ) = -L/usr/local/mysql/lib -lmysqlclient -lpthread
mysql_config (guessed ) = mysql_config
nocatchstderr (default ) = 0
nofoundrows (default ) = 0
ssl (guessed ) = 0
testdb (default ) = test
testhost (default ) =
testpassword (User's choice) = r00t!
testsocket (default ) =
testuser (User's choice) = root
To change these settings, see 'perl Makefile.PL --help' and
'perldoc INSTALL'.
Multiple copies of Driver.xst found in: /Library/Perl/5.10.0/darwin-thread-multi-2level/auto/DBI/ /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/auto/DBI/ at Makefile.PL line 907
Using DBI 1.616 (for perl 5.010000 on darwin-thread-multi-2level) installed in /Library/Perl/5.10.0/darwin-thread-multi-2level/auto/DBI/
Writing Makefile for DBD::mysql
Everything seemed to be going fine, until I tried to run make test :
t/00base....................NOK 2/6# Tried to use 'DBD::mysql'.
# Error: Can't load '/Users/swm/.cpan/build/DBD-mysql-4.018-Pnd2qz/blib/arch/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Users/swm/.cpan/build/DBD-mysql-4.018-Pnd2qz/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.16.dylib
# Referenced from: /Users/swm/.cpan/build/DBD-mysql-4.018-Pnd2qz/blib/arch/auto/DBD/mysql/mysql.bundle
# Reason: image not found at /System/Library/Perl/5.10.0/darwin-thread-multi-2level/DynaLoader.pm line 207.
# at (eval 7) line 2
# Compilation failed in require at (eval 7) line 2.
# BEGIN failed--compilation aborted at (eval 7) line 2.
FAILED--Further testing stopped: Unable to load DBD::mysql
make: *** [test_dynamic] Error 9
It's failing because it can't seem to find the mysql.bundle for DBD. Has anyone come across this problem? Or can point me in the right direction on what to try next? I need DBI/DBD::MySQL for my new job and I'm scrambling to find a solution.
Many thanks in advance.
I got around the "Library not loaded: libmysqlclient.16.dylib" problem by placing a symbolic link in /usr/lib/" to /usr/local/mysql-5.5.8-osx10.6-x86_64/lib/libmysqlclient.16.dylib
I worked around the same or a similar issue. Somehow I could build and test DBD::mysql with cpan but when I tried to use it in a script it said things like
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Library/Perl/5.10.0/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
Expected in: flat namespace
Apparently, it's a 64-bit vs 32-bit issue.
Installing the fink dbd-mysql-pm5100 package made it work though it took kind of a long time. I also removed the cpan-installed version:
sudo rm -rf /Library/Perl/5.10.0/darwin-thread-multi-2level/auto/DBD/mysql
sudo rm -rf /Library/Perl/5.10.0/darwin-thread-multi-2level/DBD/mysql
sudo rm -rf /Library/Perl/5.10.0/darwin-thread-multi-2level/DBD/mysql.pm
also include in .profile
export VERSIONER_PERL_PREFER_32_BIT=yes;
Besides creating the link the executions of the program with DBI::mysql generated an error, thus including this variable on the environment make it works
I know this is an old post. But I suppose the best solution would be to add the library directory to the DYLD_FALLBACK_LIBRARY_PATH env variable. (reason here: https://stackoverflow.com/a/3172515/119958 )
There is no ldconfig in mac, so just add the path to this env var and rerun the install process for DBD::mysql
Donato-Vianas-MacBook-Pro:Invoicer donato$ cpanm DBD::mysql
--> Working on DBD::mysql
Fetching http://www.cpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz ... OK
Configuring DBD-mysql-4.022 ... OK
Building and testing DBD-mysql-4.022 ... FAIL
! Installing DBD::mysql failed. See /Users/donato/.cpanm/build.log for details.
# Failed test 'use DBD::mysql;'
# at t/00base.t line 21.
# Tried to use 'DBD::mysql'.
# Error: Can't load '/Users/donato/.cpanm/work/1359948144.491/DBD-mysql-4.022/blib/arch/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Users/donato/.cpanm/work/1359948144.491/DBD-mysql-4.022/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib
Donato-Vianas-MacBook-Pro:Invoicer donato$ export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_FALLBACK_LIBRARY_PATH
Donato-Vianas-MacBook-Pro:Invoicer donato$ cpanm DBD::mysql--> Working on DBD::mysql
Fetching http://www.cpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz ... OK
Configuring DBD-mysql-4.022 ... OK
Building and testing DBD-mysql-4.022 ... OK
Successfully installed DBD-mysql-4.022
1 distribution installed
Donato's solution works for install, but the var has to be present at runtime as well or I get the same error. The following fixes this at runtime for shell and _www user:
# For command line use, add following line to ~/.bash_profile:
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_FALLBACK_LIBRARY_PATH
# If Apache needs it, add following line to /etc/apache2/httpd.conf:
# On Lion Server, I put it after <IfDefine MACOSXSERVER>, but shouldn't matter
SetEnv DYLD_FALLBACK_LIBRARY_PATH /usr/local/mysql/lib/:$DYLD_FALLBACK_LIBRARY_PATH
It's somewhat of an aside, but I strongly recommend setting up a separate perl on the machine -- either by fink / macports, or from source -- and leaving the Mac's system perl (and its libraries) alone.
Once I did this on my own Mac, I had very few troubles installing modules thereafter, and I didn't have to worry about accidentally blowing a hole in my OS by breaking the perl that the system uses.
If it were my Mac, I'd install a new perl from source (the Perl source distribution is smart enough to install itself see that it's on a Mac and install itself safely into /usr/local/bin) and the proceed from thee to install DBD::Mysql (and the other modules you require).