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

How do you connect to the mysql db using perl?
I'm currently doing this:
my $dbh = DBI->connect('DBI:mysql:rumpus.plus.net', $username, $passwo +rd) or die "error"; <br>
But get an error message (on the cmd line) as follows;
DBI->connect(rumpus.plus.net) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' ...
Any help would be great.
Thanks
Chris

Replies are listed 'Best First'.
Re: Connecting to mysql using perl
by valdez (Monsignor) on Feb 07, 2003 at 09:31 UTC

    It seems that MySQL isn't running...

    Ciao, Valerio

Re: Connecting to mysql using perl
by Massyn (Hermit) on Feb 07, 2003 at 09:46 UTC

    Is mySQL on the same machine where the script is running? Is it a Linux/Unix machine? The way you're using it, it seems like you're trying to make the connection to the local machine, and mysql probably isn't running.

    I used mySQLpp as opposed to your mysql module. Have a look at it. It works similar to mysql. Also read through the docs. I know that's not always the answer you're looking for, but the answers you're looking for are in there.

    cheers...Phil

Re: Connecting to mysql using perl
by zengargoyle (Deacon) on Feb 07, 2003 at 09:31 UTC

    from perldoc DBD::mysql

    SYNOPSIS
    
    use DBI; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$por +t"; $dbh = DBI->connect($dsn, $user, $password);
Re: Connecting to mysql using perl
by iburrell (Chaplain) on Feb 07, 2003 at 20:05 UTC
    What your code is saying is that you want to connecto the database called 'rumpus.plus.net' on the local host. What you likely mean is that you want to connect to the host named 'rumpus.plus.net' and use some unspecified database. The DBD::mysql documentation describes the correct syntax to specify the host and database.
    my $host = 'rumpus.plus.net'; my $database = 'somedatabase'; my $dbh = DBI->connect("dbi:mysql:database=$database;host=$host", $use +rname, $password);
Re: Connecting to mysql using perl
by jammin (Novice) on Feb 07, 2003 at 10:08 UTC
    I've had this problem on several occasions and it sounds as though it wasn't quite configured correctly when installed. Rather than hacking it now, I would seriously recommend that you reinstall which would be the quickest. I think it has been configured to look in the wrong directory, check while you re-install. Good luck.