Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl DBI

Reply
Thread Tools

perl DBI

 
 
sangeetha
Guest
Posts: n/a
 
      08-05-2003
Hi Experts,

I'm new to PERL DBI programming i've writen following perl DBI
program, It seems it is nt able to connect to MySQL.

>>>>>>>>>>>>>> Program <<<<<<<<<<<<<<<<<<<


#!perl

use warnings;
use strict;

use DBI;

my $dbh;

$dbh = DBI->connect('dbi:mysql:test','root','pepsi');

unless ($dbh) {
print "Error opening database: $DBI::errstr\n";
exit ;
}

my $connected = $dbh->ping;

if ($connected and not int($connected)) {
print "ping not implemented by '", $dbh->{driver}->{Name},"'.\n";
} else {
print "Connection is live\n";
}

$dbh->disconnect();

<<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>

Output Error message:

DBI connect('test','root',...) failed: Can't connect to local MySQL
server through socket '/tmp/mysql.sock' (2) at db.pl line 10
Error opening database: Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2)

<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>

Please note i'm able to check my (test) table directly login into
"mysql" by "mysql -u root -p" ... checked "mysqld" is running in
localhost.. MySQL version is "mysql Ver 11.18 Distrib 3.23.56, for
redhat-linux-gnu (i386)".

Tried:
Modified the "/etc/my.cnf" file to point the "socket" file to
"/var/lib/mysql//mysql.sock". for the header of "[client] and
[mysqld]" even now it's not working....

Please point where it goes wrong.

Thanks,
Sangeetha.
 
Reply With Quote
 
 
 
 
Jim Rendant
Guest
Posts: n/a
 
      08-07-2003
Try running mysql as some one other than root.

Check your permissions on the /var/lib/mysql directory. It drove me nuts for
a while but this may be the problem. This directory should be owned by mysql
with the group mysql.


"sangeetha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi Experts,
>
> I'm new to PERL DBI programming i've writen following perl DBI
> program, It seems it is nt able to connect to MySQL.
>
> >>>>>>>>>>>>>> Program <<<<<<<<<<<<<<<<<<<

>
> #!perl
>
> use warnings;
> use strict;
>
> use DBI;
>
> my $dbh;
>
> $dbh = DBI->connect('dbi:mysql:test','root','pepsi');
>
> unless ($dbh) {
> print "Error opening database: $DBI::errstr\n";
> exit ;
> }
>
> my $connected = $dbh->ping;
>
> if ($connected and not int($connected)) {
> print "ping not implemented by '", $dbh->{driver}->{Name},"'.\n";
> } else {
> print "Connection is live\n";
> }
>
> $dbh->disconnect();
>
> <<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>
>
> Output Error message:
>
> DBI connect('test','root',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at db.pl line 10
> Error opening database: Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
>
> <<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> Please note i'm able to check my (test) table directly login into
> "mysql" by "mysql -u root -p" ... checked "mysqld" is running in
> localhost.. MySQL version is "mysql Ver 11.18 Distrib 3.23.56, for
> redhat-linux-gnu (i386)".
>
> Tried:
> Modified the "/etc/my.cnf" file to point the "socket" file to
> "/var/lib/mysql//mysql.sock". for the header of "[client] and
> [mysqld]" even now it's not working....
>
> Please point where it goes wrong.
>
> Thanks,
> Sangeetha.



 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      08-07-2003
> $dbh = DBI->connect('dbi:mysql:test','root','pepsi');

You could try:

$dbh =
DBI->connect('dbi:mysql:database=test;host=localhost', 'root','pepsi');

and see if that works for you (this is a syntax from the DBD::mysql
documentation).

You could also add the following after the connect line:

DBI->(4, "tracefile.txt");

This will create a verbose trace file for your review. It will
describe the "conversation" between your script and the database.
This will help to diagnose where the failure is (ie MySQL
mis-configuration, MySQL not running, etc.).


> <<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>
>
> Output Error message:
>
> DBI connect('test','root',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at db.pl line 10
> Error opening database: Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
>


Check to see if your MySQL database server is configured to allow
connections from sources other than the mysql client. It is my
understanding that you need to allow connections to MySQL from
something other than the socket it opens - you need to allow
connections to port 3306 (or some variation). You also need to check
the MySQL log file to see if the database is being contacted and
what's it's doing when it is contacted.

I'd check MySQL first, because the error you're getting is more likely
created because of something with the way MySQL is set up versus the
way you wrote the script. The trace file and checking of the logs
will verify or invalidate what I've said.

HTH

Jim

P.S. - ALWAYS remove passwords from posts (I now know your root
password for MySQL is 'pepsi'). I HOPE that you included the password
as an example and it's NOT really the password. Use something like
'foo' or 'bar' - we'll all know that should be an example versus a
real password. And you should NEVER set up 'root' with accounts to
such things as a database unless you have a very valid reason to do
so. root has enough power as is - no sense in giving the root account
any more power without a good reason to do so - use another account
for
superuser or admin fuctions in MySQL.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DBI Mysql storing DBI:binary, trouble with character 26 Jerome Hauss Ruby 0 10-13-2004 03:04 PM
DBI and DBI::Oracle packages configuration ulloa Perl 1 07-22-2004 05:52 PM
last_insert_id() in perl/DBI Irene Mettias Perl 0 09-22-2003 06:13 PM
DBI problem : How can I load quickly one huge table with DBI ??. Tim Haynes Perl Misc 3 09-13-2003 03:43 AM
Mason, DBI, and DBI::Pg Asby Perl Misc 0 07-24-2003 09:04 PM



Advertisments