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

I am attempting to install the perl module DBD::MariaDB or the module DBD::mysql. I am using strawberry perl version 40. It is supposed to have these modules installed out of the box, but these modules are not present. I checked this with instmodsh.bat and I have also tried to access a database. When I try to access the database, it states that the module is not installed and provides a number of options but mysql and MariaDB are not present. I have tried to install the module using CPAN and I get the message that the installer cannot find "mysql.h". I checked for this file and it is present in the Ampss\mysql\include directory. I have tried adding this to the system path variable, using the commandline switch --cflags=-IC:\Ampss\mysql\include. I have tried creating the mysql_config file mentioned in the install documentation, but the installer was never able to find the file. Any suggestions on what I am doing wrong or how to get around this problem?

Replies are listed 'Best First'.
Re: MySQL/MariaDB DBD install problem
by dasgar (Priest) on Sep 16, 2024 at 21:05 UTC

    Did a little bit of investigation of documentation. Although DBD::mysql::INSTALL makes a claim that Strawberry Perl comes with DBD::mysql, DBD::MariaDB::INSTALL does not make a similar claim about DBD::MariaDB.

    After doing some digging around on Strawberry Perl's releases page, it looks like version 5.36.1.1 does include DBD::mysql, but it was dropped starting with the next released version (5.36.3.1). Unless you really need be on version 5.40, you should be able to download Strawberry Perl 5.36.1.1 to interact with MySQL. (If you want to do a quick test without installing another version of Strawberry Perl, you can download the portable edition.) Otherwise, the install links above might be good starting points on trying to troubleshoot your install efforts for those two modules.

      For what it's worth cygwin currently comes with Perl 5.40.0, DBI 1.644, and DBD::mysql 4.052, and cpanm DBD::MariaDB works from a cygwin terminal.
      $ cpanm DBD::MariaDB --> Working on DBD::MariaDB Fetching http://www.cpan.org/authors/id/P/PA/PALI/DBD-MariaDB-1.23.tar +.gz ... OK Configuring DBD-MariaDB-1.23 ... OK Building and testing DBD-MariaDB-1.23 ... OK Successfully installed DBD-MariaDB-1.23 1 distribution installed
Re: MySQL/MariaDB DBD install problem
by syphilis (Archbishop) on Sep 17, 2024 at 01:29 UTC
    I have tried to install the module using CPAN and I get the message that the installer cannot find "mysql.h".

    Simplest way to ensure that the unlocatable "mysql.h: is found is to:
    set CPATH=C:\Ampss\mysql\include;%CPATH%
    prior to running cpan.
    You might also need to set the LIBRARY_PATH environment variable to locate the mysql library (.a) files.

    I'm assuming this mysql library that you have is compatible with strawberry's gcc-13.2.0 compiler.
    You might also get good help by filing an issue about this at https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues.

    Cheers,
    Rob

      Thank you for your response. This did not fix the problem. I have since migrated to SQLite (which was included with strawberry perl). I am not doing anything really stressful (no multiple users or access over a network).<\P>

        To install DBD-Maria-1.22 onto latest StrawberryPerl-5.40.0, I copied over the libmysql stuff from StrawberryPerl-5.38.2 (portable edition).
        That is:
        1) copy mysql_config.bat from SP-5.38.2/c/bin to SP-5.40.0/c/bin;
        2) copy libmysql__.dll from SP-5.38.2/c/bin to SP-5.40.0/c/bin;
        3) copy libmysql.a from SP-5.38.2/c/lib to SP-5.40.0/c/lib;
        4) copy the mysql50716 folder from SP-5.38.2/c/include to SP-5.40.0/c/include;

        Then I built and installed the module manually from downloaded source (by running perl Makefile.PL, then gmake test, then gmake install).
        You could also install version 1.22 using either the cpan or cpanm utilities - but you have to direct it to grab the 1.22 source.

        Version 1.23 won't build against that library because the symbol __imp___pioinfo can't be resolved.
        If you can substitute in a (presumably more recent) mysql library that resolves that symbol, then you should be able to install version 1.23.

        Cheers,
        Rob
Re: MySQL/MariaDB DBD install problem
by Danny (Chaplain) on Sep 16, 2024 at 16:53 UTC
    I would first double check that the @INC variable contains the correct paths and then double check that mysql.pm is not in them with something like:
    perl -wE 'for my $d (@INC) { -s "$d/DBD/mysql.pm" and say "$d/DBD/mysq +l.pm" }'
    If it's not present I would go back to the original installation and figure out why they weren't installed. If they are supposed to be there but are not, then something may be wrong with your installation in general.

    Also probably worth looking at perl -V | grep version to make sure you are using the perl you think you are using.

      I tried the statement and it produced an error "Can't find string terminator "'" anywhere before EOF at -e on line 1." This was a cut and paste so the chance of a typo is low. Is this statement for linux? I am using windows command line.

        This is an example where I think a better idiom for telling people to run commands isn't to give them a shell-prompt starting point, but a Perl one, so here:
        $ perl -wE 'for my $d (@INC) { -s "$d/DBD/mysql.pm" and say "$d/DBD/my +sql.pm" }'
        would become:
        C:\strawberry>perl -de 0 Loading DB routines from perl5db.pl version 1.57 Editor support available. Enter h or 'h h' for help, or 'perldoc perldebug' for more help. main::(-e:1): 0 [errors from Term::ReadKey to be ignored] DB<1> for my $d (@INC) { -s "$d/DBD/mysql.pm" and say "$d/DBD/mysql. +pm" } C:/strawberry/perl/vendor/lib/DBD/mysql.pm
        That would then be immune to the vagaries of Windows command lines.
        Yeah unfortunately the Windows command line doesn't treat ' as quote characters, so the whole thing would need to be inside double-quotes, and the perl strings within would need to be a different quoting syntax like qq{...}. The Windows command line is much less useful for one-liners than Bash. This is yet another good argument for Cygwin, since cygwin provides a fully unix-compatible terminal window.

        If you already have code written for Strawberry, though, switching to cygwin perl means you have to check all your usage paths to make sure they are forward-slashes.

Re: MySQL/MariaDB DBD install problem
by Marshall (Canon) on Sep 16, 2024 at 16:41 UTC
    Please show your code for connecting to the DB. Should be something like this for mysql:
    use strict; use warnings; use DBI; $dbh = DBI->connect('DBI:mysql:databasename', 'username', 'password' ) || die "Could not connect to database: $DBI::errstr";
      My code is pretty much identical to the code you posted. I get the message that either "mysql" is spelled wrong or the capitalization is incorrect or the DBD::mysql module is not installed. Checking the installed modules with instmodsh.bat, it shows the DBD::mysql module is not installed. When I attempt to install the module using CPAN, I see the error that the makefile.pl does not find the file "mysql.h".