The below is part of the output when receiving an error attempting to install the Perl DBD::mysql module using the CPAN shell. I rarely use the Perl CPAN shell since most of the packages are available on CentOS, my typical Linux distribution choice for servers, using the yum package manager. In this case I was working on installing Monarch on a server at work to assist with Nagios file management. Monarch allows you to backup the entire Nagios configuration files with the click of a button. Monarch will also provide a visual view of any Nagios build errors, Nagios configuration files (including users, user groups, services, check commands, etc.,), and more. So when attempting to build the Perl DBD:mysql module via the CPAN shell I received some errors which I initially did not understand because they did not explain the specific issue however I eventually located the problem which ended up being easy to resolve. Below I describe the error in detail as well as information on how to resolve.
CPAN Shell Command Used To Install Perl DBD:mysql Module:
- cpan> install DBD::mysql
The below is only a section of the output of the attempt to install the Perl DBD::mysql module using the Perl CPAN shell.
Errors Installing Perl DBD::mysql Module Using CPAN Shell:
- CPAN: File::Temp loaded ok (v0.22)
- CPAN.pm: Going to build C/CA/CAPTTOFU/DBD-mysql-4.013.tar.gz
- PLEASE NOTE:
- For 'make test' to run properly, you must ensure that the
- database user 'root' can connect to your MySQL server
- and has the proper privileges that these tests require such
- as 'drop table', 'create table', 'drop procedure', 'create procedure'
- as well as others.
- mysql> grant all privileges on test.* to 'root'@'localhost' identified by 's3kr1t';
- You can also optionally set the user to run 'make test' with:
- perl Makefile.pl --testuser=username
- I will use the following settings for compiling and testing:
- cflags (mysql_config) = -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv
- embedded (mysql_config) =
- libs (mysql_config) = -rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto
- mysql_config (guessed ) = mysql_config
- nocatchstderr (default ) = 0
- nofoundrows (default ) = 0
- ssl (guessed ) = 1
- testdb (default ) = test
- testhost (default ) =
- testpassword (default ) =
- testsocket (default ) =
- testuser (guessed ) = root
- To change these settings, see 'perl Makefile.PL --help' and
- 'perldoc INSTALL'.
- Argument "6.55_02" isn't numeric in numeric ge (>=) at Makefile.PL line 350, <PIPE> line 93.
- Checking if your kit is complete...
- Looks good
- Unrecognized argument in LIBS ignored: '-rdynamic'
- Using DBI 1.609 (for perl 5.010001 on i686-linux) installed in /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/auto/DBI/
- Writing Makefile for DBD::mysql
The errors above which eventually pointed me in the right direction for resolution were not at the end of the installation output so don’t expect the install to fail immediately after seeing the above errors installing DBD::mysql. The below CPAN output is what was displayed at the very end of the Perl CPAN output.
Ending CPAN Output Of A Failed Attempt To Install The Perl DBD::mysql Module:
- dbdimp.c:4663: warning: passing argument 1 of â€˜Perl_sv_2mortalâ€™ makes pointer from integer without a cast
- make: *** [dbdimp.o] Error 1
- /usr/bin/make -- NOT OK
- Warning (usually harmless): 'YAML' not installed, will not store persistent state
- Running make test
- Can't test without successful make
- Running make install
- Make had returned bad status, install seems impossible
- Failed during this command:
- CAPTTOFU/DBD-mysql-4.013.tar.gz : make NO
To resolve the error you simply need to install the mysql-devel package which can be completed on CentOS using the yum package manager. The command to install mysql-devel on CentOS is displayed in the below example.
Install The mysql-devel Package On CentOS Linux Using Yum:
- [root@server src]# yum install mysql-devel
Once you have installed the mysql-devel package launch the CPAN shell again to attempt the DBD::mysql package which should provide the end result showing the package installed properly this time.
Successfully Install DBD:mysql Using CPAN Shell:
- Running make install
- Prepending /root/.cpan/build/DBD-mysql-4.013-Gf1DDv/blib/arch /root/.cpan/build/DBD-mysql-4.013-Gf1DDv/blib/lib to PERL5LIB for 'install'
- Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/auto/DBD/mysql/mysql.so
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/auto/DBD/mysql/mysql.bs
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/Bundle/DBD/mysql.pm
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/DBD/mysql.pm
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/DBD/mysql/GetInfo.pm
- Installing /usr/local/lib/perl5/site_perl/5.10.1/i686-linux/DBD/mysql/INSTALL.pod
- Installing /usr/local/share/man/man3/DBD::mysql.3
- Installing /usr/local/share/man/man3/DBD::mysql::INSTALL.3
- Installing /usr/local/share/man/man3/Bundle::DBD::mysql.3
- Appending installation info to /usr/local/lib/perl5/5.10.1/i686-linux/perllocal.pod
- /usr/bin/make install -- OK
The CPAN command that produced the initial errors and then provided the successful result displayed above is displayed in the below example. I had seen in other attempted resolutions on the web where people tried to create a MySQL database named test which can be accessed by the “root” MySQL user. While it does make sense why some might think the problem can be resolved by doing this it will not resolve the issue because CPAN will still be missing the libraries it needs to issue the commands that are attempting to be run.
You should now be able to use the MySQL API to interface Perl code with MySQL.