PDA

View Full Version : Can't connect to MySQL trough Perl DBI



Alejandro
08-08-2006, 12:52 AM
-Don't know if this question is for perl or for mysql so I posted in both-

I have 2 accounts in WH and the very same perl program works fine in one of them and in the other seems like it can't connect (Im not sure that's the problem but I think so, I always get empty vars)

The lines I'm using:

------------------------------------------------
use DBI;

$driver = "DBI:mysql";
$user = "xxx";
$password = "xxx";
$database = "xxx";
$table = "xxx";

$dbh = DBI -> connect ("$driver:$database", $user, $password)
or die "Cannot connect";
my $sql = qq{ SELECT var1,var2,var3 FROM $table WHERE id = ? };
my $sth = $dbh->prepare($sql);
$sth->execute($id);
my $datos = $sth->fetchall_arrayref;
$vvar1 = $datos->[0][0];
$vvar2 = $datos->[0][1];
$dbh -> disconnect;
------------------------------------------------

It WORKS on: (old account)

MySQL 3.23.56 // PerlMySQL 1.1 // Perl 5.6.0

It DOES NOT work on: (just setup account)

MySQL4 4.1.9 // PerlMySQL 1.48 // Perl 5.8.7

Dont really know if the versions have something to do or if Perl DBI is installed in both (BTW how may I check that?)

Please help...

Alejandro
08-08-2006, 10:14 PM
Went to the error log and I get the following:

DBI connect('xxx','xxx',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at xxx.pm line 12

any ideas???

torrin
08-09-2006, 07:30 AM
DBI connect('xxx','xxx',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at xxx.pm line 12

Does /tmp/mysql.sock exist? I had to modify the mysql startup script to create that link everytime it's restarted.

blender
08-09-2006, 07:38 AM
I feel like this info has been posted before but I couldn't find it so I'll post it again just in case.

WH puts the mysql.sock file in /var/lib/mysql/ by default, but that isn't where Perl is looking for it. To fix this you can do the following:

1. Stop mysql ( "/etc/rc.d/init.d/mysqld stop" )
2. Edit /etc/my.cnf and comment out the lines that tell mysql to put the mysql.sock in /var/lib/mysql/
3. restart mysql ( "/etc/rc.d/init.d/mysqld start" )

Now if you look in /tmp/ your mysql.sock should exist there. But since we don't want to break any WH apps that may be expecting the mysql.sock in the other location (speaking from experience here), do this last step:

4. go to /var/lib/mysql/ and run the following command:
ln -s ../../../tmp/mysql.sock

Again, speaking from experience, make sure you enter the command as shown, and not
"ln -s /tmp/mysql.sock"
because some apps don't like it that way.

Hope that helps.

wildjokerdesign
08-09-2006, 07:53 AM
Blender,
Do you know if WH is aware of this? Seems like it would make more sense to for them to change the default of either perl or mysql so folks would not have to make the manual edit.

Alejandro
08-09-2006, 12:15 PM
torin/blender:

It was just like you said. That file didn't existed and I had to do it manually according to blender's procedure and now it is working as it should..

THANK YOU