Geert86 has asked for the wisdom of the Perl Monks concerning the following question:

When installing DBD::mysql I received two errors:

install DBD::mysql =>
An error occurred while linking the DBD::mysql driver. The error
message seems to indicate that you don't have a libz.a,
or a libz.so. There are a few ways to resolve this:

1) You may try to remove the -lz or -lgz flag from the libs list
   by using the --libs switch for "perl Makefile.PL".
2) On Red Hat Linux and SUSE Linux, install the zlib-devel package
   (sometimes called libz-devel)
3) On Debian and Ubuntu, install the zlib1g-dev package
4) On other systems, please contact the mailing list

     perl@lists.mysql.com

For further hints, see INSTALL.html, section Linker flags.
make: *** blib/arch/auto/DBD/mysql/mysql.so Error 1
  /usr/bin/make  -- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible
So I installed zlib1g-dev
Then I tried to install it again, and I got this error:

install DBD::mysql =>
Running install for module DBD::mysql
Running make for C/CA/CAPTTOFU/DBD-mysql-4.007.tar.gz
  Is already unwrapped into directory /root/.cpan/build/DBD-mysql-4.007
  Has already been processed within this session
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible
I removed the directory /root/.cpan/build/DBD-mysql-4.007 but after a retry I had the same error.

I must say I am a total noob on PERL and CPAN, so I hope it is an easy fix.

Best regards,

Geert

Replies are listed 'Best First'.
Re: Error installing DBD::mysql on Debian
by moritz (Cardinal) on Jul 23, 2008 at 08:56 UTC
    Normally it's best to install DBD::mysql via apt on Debian:
    sudo aptitude install libdbd-mysql-perl

    Debian provides native packages for the most commonly used CPAN modules, all of which have the form libfoo-bar-perl for a package Foo::Bar

    That being said, if you still want to install it via cpan, you can at least satisfy all build dependencies with apt:

    sudo apt-get build-dep libdbd-mysql-perl

    And then try again.

Re: Error installing DBD::mysql on Debian
by Arunbear (Prior) on Jul 23, 2008 at 11:23 UTC
    I had the same problem yesterday on Centos, (and tried the same things you did and got the same results).

    Then I tried:

    $ ls -l /usr/lib/libz* lrwxrwxrwx 1 root root 15 Feb 14 20:24 /usr/lib/libz.so.1 -> libz. +so.1.2.1.2 -rwxr-xr-x 1 root root 63624 Jul 21 2005 /usr/lib/libz.so.1.2.1.2
    i.e. there was no libz.so, so I made a symlink to it:
    $ ln -s /usr/lib/libz.so.1.2.1.2 /usr/lib/libz.so $ ls -l /usr/lib/libz* lrwxrwxrwx 1 root root 24 Jul 22 12:10 /usr/lib/libz.so -> /usr/li +b/libz.so.1.2.1.2 lrwxrwxrwx 1 root root 15 Feb 14 20:24 /usr/lib/libz.so.1 -> libz. +so.1.2.1.2 -rwxr-xr-x 1 root root 63624 Jul 21 2005 /usr/lib/libz.so.1.2.1.2
    and this allowed the install to succeed.

Re: Error installing DBD::mysql on Debian
by Anonymous Monk on Jul 23, 2008 at 08:58 UTC
    look DBD::mysql make realclean perl Makefile.PL make make test
      Alternatively, at the cpan prompt:
      cpan> clean DBD::mysql
      You should then be able to try your install again
Re: Error installing DBD::mysql on Debian
by LesleyB (Friar) on Jul 23, 2008 at 18:35 UTC

    I run Debian stable and have ventured into using CPAN to install more up to date modules. You should certianly be able to get a working system out of the Debian repository.

    You can configure the command cpan to chase down dependencies but be aware this may lead to trouble. At some point after I'd used cpan to update some modules, an apt-get upgrade failed because it picked up the Errno.pm in my /usr/local/share/perl/5.8.8 instead of the Errno in /usr/share/perl/5.8.8.

    I think the preferred method within Debian is to download the Debian packages and not to use cpan. These have a naming convention of lib<modulename>-perl e.g. libcgi-perl and libcgi-formbuilder-perl. You could use apt-cache search to hunt for a specific package name.