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

If I try to run a script from a login I get this response even though DBD::mysql exists on every path in the error:

Opening the database
install_driver(mysql) failed: Can't locate loadable object for module DBD::mysql in @INC (@INC contains: . /usr/local/lib/perl5/site_perl/5.38.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.38.2 /usr/local/lib/perl5/5.38.2/x86_64-linux /usr/local/lib/perl5/5.38.2) at (eval 6) line 3. Compilation failed in require at (eval 6) line 3. Perhaps a module that DBD::mysql requires hasn't been fully installed

HOWEVER.... I can run it in my browser with no errors

Why is this??

Replies are listed 'Best First'.
Re: mysql error
by LanX (Saint) on Feb 16, 2024 at 17:14 UTC
    > exists on every path in the error:

    Do you say it's installed for each path listed? Seriously?

    Could you show us at least one of these paths?

    > HOWEVER.... I can run it in my browser with no errors

    I suppose you are talking about a CGI script called via a webserver like Apache?

    Webservers can have their own environment set in their configs. You might want to dump $ENV{PERL5LIB} and similar into your HTML to check.

    Probably your are even using another Perl installation?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      You are right about different versions of perl:
      which perl
      /usr/local/bin/perl

      Script: #!/usr/bin/perl

      If I change the script to: #!/usr/local/bin/perl
      It chokes.

      Do you know how I can change perl to /usr/bin/perl in debian 8?

        It's the order in your $PATH environmental variable:
        echo $PATH
        You can change the order to put /usr/bin/ before /usr/local/bin. Or instead of running the script like
        perl script_name.pl
        just run
        ./script_name.pl
      /usr/local/lib/perl5/site_perl/5.38.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.38.2 /usr/local/lib/perl5/5.38.2/x86_64-linux /usr/local/lib/perl5/5.38.2)
      The best I can tell, $ENV{PERL5LIB} is empty. @e = $ENV{PERL5LIB}; $n = @e; $l = length(@e); print "l = $l
      \n"; print "n= $n
      \n"; print "@e"; print "
      \n"; This returns nothing either from my browser or the command line.
Re: mysql error
by Danny (Chaplain) on Feb 16, 2024 at 17:41 UTC
    You might try
    printf STDERR "%s\n", join "\n", @INC;
    and compare the command line output to the CGI output to get an idea of which modules are being used.
      I don't know what this means: root@localhost:/var/www/4# printf STDERR "%s\n", join "\n", @INC STDERRroot@localhost:/var/www/4#
        Maybe instead write the @INC list to a file so it's easier to see like so:
        { my $fh; open $fh, ">", "/tmp/inc.$$"; printf $fh "%s\n", scalar localtime; printf $fh "%s\n", join "\n", @INC; }