If Perl reports that it cannot find the
../mysql/mysql.so
module, the problem is
probably that Perl cannot locate the
libmysqlclient.so
shared library. You should
be able to fix this problem by one of the following methods:
Compile the DBD::mysql
distribution with
perl Makefile.PL -static -config
rather
than perl Makefile.PL
.
Copy libmysqlclient.so
to the directory
where your other shared libraries are located (probably
/usr/lib
or /lib
).
Modify the -L
options used to compile
DBD::mysql
to reflect the actual location
of libmysqlclient.so
.
On Linux, you can add the path name of the directory where
libmysqlclient.so
is located to the
/etc/ld.so.conf
file.
Add the path name of the directory where
libmysqlclient.so
is located to the
LD_RUN_PATH
environment variable. Some
systems use LD_LIBRARY_PATH
instead.
Note that you may also need to modify the -L
options if there are other libraries that the linker fails to
find. For example, if the linker cannot find
libc
because it is in /lib
and the link command specifies -L/usr/lib
, change
the -L
option to -L/lib
or add
-L/lib
to the existing link command.
If you get the following errors from
DBD::mysql
, you are probably using
gcc (or using an old binary compiled with
gcc):
/usr/bin/perl: can't resolve symbol '__moddi3' /usr/bin/perl: can't resolve symbol '__divdi3'
Add -L/usr/lib/gcc-lib/... -lgcc
to the link
command when the mysql.so
library gets built
(check the output from make for
mysql.so
when you compile the Perl client).
The -L
option should specify the path name of the
directory where libgcc.a
is located on your
system.
Another cause of this problem may be that Perl and MySQL are not both compiled with gcc. In this case, you can solve the mismatch by compiling both with gcc.
You may see the following error from DBD::mysql
when you run the tests:
t/00base............install_driver(mysql) failed: Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql: ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol: uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
This means that you need to include the -lz
compression library on the link line. That can be done by changing
the following line in the file
lib/DBD/mysql/Install.pm
:
$sysliblist .= " -lm";
Change that line to:
$sysliblist .= " -lm -lz";
After this, you must run make realclean and then proceed with the installation from the beginning.
If you want to install DBI on SCO, you have to edit the
Makefile
in
DBI-xxx
and each subdirectory. Note
that the following assumes gcc 2.95.2 or newer:
OLD: NEW: CC = cc CC = gcc CCCDLFLAGS = -KPIC -W1,-Bexport CCCDLFLAGS = -fpic CCDLFLAGS = -wl,-Bexport CCDLFLAGS = LD = ld LD = gcc -G -fpic LDDLFLAGS = -G -L/usr/local/lib LDDLFLAGS = -L/usr/local/lib LDFLAGS = -belf -L/usr/local/lib LDFLAGS = -L/usr/local/lib LD = ld LD = gcc -G -fpic OPTIMISE = -Od OPTIMISE = -O1 OLD: CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include NEW: CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
These changes are necessary because the Perl dynaloader does not
load the DBI
modules if they were compiled with
icc or cc.
If you want to use the Perl module on a system that does not
support dynamic linking (such as SCO), you can generate a static
version of Perl that includes DBI
and
DBD::mysql
. The way this works is that you
generate a version of Perl with the DBI
code
linked in and install it on top of your current Perl. Then you use
that to build a version of Perl that additionally has the
DBD
code linked in, and install that.
On SCO, you must have the following environment variables set:
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
Or:
LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\ /usr/progressive/lib:/usr/skunk/lib LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\ /usr/progressive/lib:/usr/skunk/lib MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\ /usr/skunk/man:
First, create a Perl that includes a statically linked
DBI
module by running these commands in the
directory where your DBI
distribution is
located:
shell>perl Makefile.PL -static -config
shell>make
shell>make install
shell>make perl
Then you must install the new Perl. The output of make perl indicates the exact make command you need to execute to perform the installation. On SCO, this is make -f Makefile.aperl inst_perl MAP_TARGET=perl.
Next, use the just-created Perl to create another Perl that also
includes a statically linked DBD::mysql
by
running these commands in the directory where your
DBD::mysql
distribution is located:
shell>perl Makefile.PL -static -config
shell>make
shell>make install
shell>make perl
Finally, you should install this new Perl. Again, the output of make perl indicates the command to use.
User Comments
The current DBD driver nolonger supports static linking. The current perl versions from the SCO site the ones in pub/openserver5/opensrc, pub/unixware7/opensrc or pub/openunix8/opensrc nolonger have problems with dynamic libraries. The shell scripts have to have the LD_LIBRARY_PATH defined in them that include the .so reguired. Use ldd from a shell prompt to check all needed libraries are found.
In opposition at what is said in the docs the minimun version of MySQL::DBD for MySQL 4.1 is the 2.9004.
The compilation of the module Perl MySQL::DBD version 2.9003 gives the following error:
mysql.xs: In function `XS_DBD__mysql__dr__admin_internal':
mysql.xs:100: too few arguments to function `mysql_shutdown'
This is because from MySQL version 4.1.3 the function mysql_shutdown has an extra parameter.
As I told before the problem is solved in the version 2.9004.
Another consideration as of this writing for DBD-mysql users is the change in password hash length:
At least under my current config (Win XP, ActiveState Perl 5.8.3, DBI 1.46, DBD-mysql 2.9004), one must either run the server with the --old-passwords option (whenever setting passwords) or set passwords using the OLD_PASSWORD() function.
Otherwise, your DBI->connect will return an error "Client does not support authentication protocol requested
by server; consider upgrading MySQL client". This is because of the change in password hashing.
See also: http://dev.mysql.com/doc/mysql/en/Old_client.html and http://dev.mysql.com/doc/mysql/en/Password_hashing.html
OK, for making the incompatibility message go away:
DBD::mysql 2.9004 did NOT work, but 3.0002 DID. It was presumably fixed between these two versions.
If you want to (as root)
perl -MCPAN -e shell
and then
install DBD::mysql
that's fine, but the root password for the database must first be set empty.
If you are trying to compile DBD::mysql under Mac 10.4.X (particularly on a Macbook pro) and are running into major problems with messages like:
Note (probably harmless): No library found for -lmysqlclient
and
dbdimp.h:21:49: error: mysql.h: No such file or directory
dbdimp.h:22:45: error: mysqld_error.h: No such file or directory
dbdimp.h:23:49: error: errmsg.h: No such file or directory
In file included from dbdimp.c:20:
dbdimp.h:124: error: parse error before 'MYSQL'
dbdimp.h:124: warning: no semicolon at end of struct or union
dbdimp.h:142: error: parse error before '}' token
and many others, you may want to see http://jayallen.org/journey/2006/04/dbd-mysql-build-problems-on-mac-book-pro for a discussion and potential solution.
The problem seems to stem from the fact that the "mysql_config" command used by the DBD::mysql build script reports incorrect values for MySQL's header and include files. To overcome the problem, you need to discover and specify the right directories with the cflags and libs options in the Makefile creation step.
Maybe I'm confused but if the DBD::mysql driver no longer supports static linking, then why doesn't the mysql 5 package come with .so files installed with it. Why does the documentation say that you can use "perl Makefile.PL -static -config" when those options obviously do not work any more. Can anyone confirm that those options would be possible with the latest DBD::mysql?
The problem:
After installing DBI and DBD::MySQL, perl-ing a DBI->connect fails with the following error:
/usr/bin/perl: symbol lookup error: /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init
The platform:
Linux athena.uio.no 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:58:43 EDT 2008 x86_64 GNU/Linux
thena.uio.no# gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)
The explanation:
DBD::mysql cannot resolve properly references to the libmysqlclient library. To resolve this issue:
1)First install DBI ( use CPAN to get the sources or manual install)
athena.uio.no# cd DBI-1.604/
athena.uio.no# make clean
rm -rf Perl.c DBI.c DBI-1.604 Perl.xsi t/zv*_*.t dbi__null_test_tmp* dbiproxy dbiprof dbilogstrip dbiproxy.*log dbitrace.log dbi.prof ndtest.prt ./blib Makefile.aperl blib/arch/auto/DBI/extralibs.all blib/arch/auto/DBI/extralibs.ld perlmain.c tmon.out mon.out so_locations pm_to_blib *.o *.a perl.exe perl perl DBI.bs DBI.bso DBI.def libDBI.def DBI.exp DBI.x core core.*perl.*.? *perl.core core.[0-9] core.[0-9][0-9] core.[0-9][0-9][0-9] core.[0-9][0-9][0-9][0-9] core.[0-9][0-9][0-9][0-9][0-9]
mv Makefile Makefile.old > /dev/null 2>&1
athena.uio.no# perl Makefile.PL --help
Unknown option: help
Invalid arguments
athena.uio.no# perl Makefile.PL
....
Writing Makefile for DBI
athena.uio.no# make; make install
2)Then install DBD::MySQL but watch out the library flags.
athena.uio.no# cd DBD-mysql-4.007/
athena.uio.no# make clean
make: *** No rule to make target `clean'. Stop.
athena.uio.no# perl Makefile.PL --cflags=-I/mn/athena/storage/mysql/include --libs="-L/mn/athena/storage/mysql/lib -lmysqlclient -lcrypt -lnsl -lm -lz -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv"
(in my system I have installed the MySQL server in a non-standard location, so I make sure that the cflags, libs and all the rest of the libraries (-l switches) are included in the Makefile).
....
You can also opti
cflags (User's choice) = -I/mn/athena/storage/mysql/include
embedded (mysql_config ) =
libs (User's choice) = -L/mn/athena/storage/mysql/lib lmysqlclient -lcrypt -lnsl -lm -lz -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv
mysql_config (guessed ) = mysql_config
nocatchstderr (default ) = 0
nofoundrows (default ) = 0
ssl (guessed ) = 0
testdb (default ) = test
testhost (default ) =
testpassword (default ) =
testsocket (default ) =
Use of uninitialized value in printf at Makefile.PL line 171, <PIPE> line 91.
testuser ( ) = root
.........................
athena.uio.no# make; make install
And now it should all work!
GM
With DBD::mysql 4.013 the option shown above does not work:
[sjmudd@c4x-64 DBD-mysql-4.013]$ pwd
/home/sjmudd/DBD-mysql-4.013
[sjmudd@c4x-64 DBD-mysql-4.013]$ perl Makefile.PL -static -config
Unknown option: static
Unknown option: config
...
So it seems the documentation here is out of date.
Add your own comment.