LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using Perl to connect to MySQL using webmin (https://www.linuxquestions.org/questions/linux-newbie-8/using-perl-to-connect-to-mysql-using-webmin-750658/)

manoj1007 08-27-2009 10:56 AM

Using Perl to connect to MySQL using webmin
 
Hi,
I wrote a test script in Webmin to see if I could connect to my mysql database

When I tried to run the script on Webmin, I got the following error


Error - Perl execution failed

install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /usr/local/webmin /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 . /usr/local/webmin/ ..) at (eval 57) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, Sponge.


The following is my script in webmin

use DBI;
&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);


$db_handle=DBI->connect("dbi:mysql:database=mysql;host=xxxx;user=root;password=xxxx")
or die "Could not connect to database: $DBI::errstr\n";


I did install the DBI module from CPAN (DBI-1.609) and the command "make install" as part of the last command to install gave the following result, which doesn't show any problems installing

Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Writing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/DBI/.packlist
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod

Can someone help me please? http://http.cdnlayer.com/lq/images/q...s_lq/icon9.gif

Thanks,

MJ

Tinkster 08-27-2009 01:06 PM

And what about
Quote:

/usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 . /usr/local/webmin/ ..) at (eval 57) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, Sponge.
?


Cheers,
Tink

manoj1007 08-31-2009 04:46 PM

DBD install
 
Hi Tinkster,
Thanks for your tip, I tried installing DBD and got the following error on make test

PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00base....................ok
t/10connect.................skipped
all skipped: ERROR: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Can't continue test

I initially had an error where it could not find the file libapreq2.so.which I found was in the wrong location, so I created a symbolic link to the file.

I went ahead with the install and did a make install, but now the script which tries to connect with the database gives the following error.

HTTP/1.0 500 Perl execution failed Server: MiniServ/0.01 Date: Mon, 31 Aug 2009 21:29:52 GMT Content-type: text/html Connection: close
Error - Perl execution failed

Couldn't connect to database: Access denied for user 'root'@'192.168.1.22' (using password: YES)

Any thoughts

Tinkster 08-31-2009 05:18 PM

Sorry mate .. I don't do MySQL as a matter of principle :)
I'm attached to my data...


Cheers,
Tink

chrism01 08-31-2009 06:02 PM

Show your Perl program, and keep in mind that the Linux root user is not(!) the same as the MySQL root user (basically the DBA acct).

manoj1007 09-01-2009 09:13 AM

Hi Chris,
Thanks for your help, but I am all set. It was a permission issue and once I gave the root user proper privileges, my script worked

chrism01 09-01-2009 11:32 PM

I'd start by just running this prog at the cli; easier to debug.
A couple of things look odd to me:

Code:

&ui_print_header(undef, $text{'index_title'}, undef, "intro", 1, 1, 0,
&help_search_link("iptables", "man", "doc"), undef, undef,desc);

Taken literally, that's one long line of code, with a nested call to sub help_search_link() in the call to ui_print_header().
I'm not convinced that's right.
Using '&' as a prefix when calling a sub is deprecated for Perl 5.x. Strictly speaking it means calling the sub by passing a reference to it, instead of calling it directly. I doubt you mean that.

I'd try debugging by commenting out everything after
Code:

print "Hello";
which should probably be
Code:

print "Hello\n";
In any case, you have unmatched table tags http://www.w3schools.com/tags/tag_td.asp and you're not using closing tags ie </td> </tr>

Also, amend the start of your prog to be
Code:

#!/usr/bin/perl -w
use strict;

See also
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials


All times are GMT -5. The time now is 06:53 PM.