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 |
And what about
Quote:
Cheers, Tink |
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 |
Sorry mate .. I don't do MySQL as a matter of principle :)
I'm attached to my data... Cheers, Tink |
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).
|
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 |
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, 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"; Code:
print "Hello\n"; Also, amend the start of your prog to be Code:
#!/usr/bin/perl -w http://perldoc.perl.org/ http://www.perlmonks.org/?node=Tutorials |
All times are GMT -5. The time now is 06:53 PM. |