Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Canot connect to the remote mysql server through those lines

by Nik (Initiate)
on Jul 01, 2007 at 19:47 UTC ( [id://624330]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks, When i http://nikos.varsa.gr i get
DBI connect('nikos_db','e_shop',...) failed: Can't connect to local My +SQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /home/ +www/nikos.varsa.gr/cgi-bin/index.pl line 20
here is the line 20 code and the followinf line just sets the enviromental variable correctly in case the script run in the remote server instead of the localhost.

I just don't see why i can't connect to the mysql server although the credentilas are correct and the myslq server name too.

#===================================================================== +========== my $db = ( $ENV{'SERVER_NAME'} !~ /freehostia/ ) ? DBI->connect('DBI:mysql:e_shop', 'root', 'supersecret', {Rais +eError=>1}) : DBI->connect('DBI:mysql:nikkou6_db:mysql3.freehostia.com', 'n +ikkou6_db', 'supersecret', {RaiseError=>1}); if( $ENV{'SERVER_NAME'} =~ /freehostia/ ) { $ENV{'DOCUMENT_ROOT'} = ' +/www/nikos.varsa.gr/' }; #===================================================================== +==========

20070701 Janitored by Corion: Changed password

Replies are listed 'Best First'.
Re: Canot connect to the remote mysql server through those lines
by snopal (Pilgrim) on Jul 01, 2007 at 20:20 UTC
    From 'perldoc DBI'
    Examples of $data_source values are: dbi:DriverName:database_name dbi:DriverName:database_name@hostname:port dbi:DriverName:database=database_name;host=hostname;port=port

    Try as I might, I don't see how: 'DBI:mysql:nikkou6_db:mysql3.freehostia.com' is following that specification.

    Assuming (big assumption) that user 'nikkou6_db' has exactly the same permissions as 'root' from the first connect sequence, you may still also have some 'non-local' permission issues for that user within your MySQL permission table. Otherwise, if you intended to connect using 'root' (very bad idea), you also have an incorrect user component in your call.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Canot connect to the remote mysql server through those lines
by shmem (Chancellor) on Jul 01, 2007 at 20:07 UTC
    Nik,

    you are here since 30.06.2003. Still didn't learn how to format posts? Have a look at Writeup Formatting Tips, please.

    That said, just print the environmental variable to STDOUT and look into the server error logs. Do you find there what you expect?

    If that's all ok, have a look whether the file '/var/run/mysqld/mysqld.sock' actually exists.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Guys, this a remote server that i have only ftp access to it and some space to upload files.

      I cant check whether the file '/var/run/mysqld/mysqld.sock' exists or not, i aksed na admin though and he definately stated that the mysql server on freehostia runs normally. I also have no access to any of the error logs.

      I switched the code to this but it still produces the same error:

      #===================================================================== +========== my $db = ( $ENV{'SERVER_NAME'} !~ /freehostia/ ) ? DBI->connect('DBI:mysql:e_shop@localhost', 'root', '*****', { +RaiseError=>1}) : DBI->connect('DBI:mysql:nikkou6_db@mysql3.freehostia.com', 'n +ikkou6_db', '*****', {RaiseError=>1}); if( $ENV{'SERVER_NAME'} =~ /freehostia/ ) { $ENV{'DOCUMENT_ROOT'} = ' +/www/nikos.varsa.gr/' }; #===================================================================== +==========
        Consult the DBI docs. Your DSN doesn't fit. snopal gave you some hints.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Keep your own log
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Canot connect to the remote mysql server through those lines
by marto (Cardinal) on Jul 01, 2007 at 20:12 UTC
    Could it be that the MySQL setup on the remote host differs from that of your 'test server'? Have you checked that /var/run/mysqld/mysqld.sock exists? Have you checked MySQL is up and running with this socket? Try something like show variables like 'socket'; within a MySQL session? For further tips I would suggest reading the documentation.

    Martin
Re: Canot connect to the remote mysql server through those lines
by davidj (Priest) on Jul 05, 2007 at 03:39 UTC
    Well, the first thing I would do is see if I can connect to the database from the commandline.You know:
    mysql -u root -p
    Since one of the databases in on your local machine, you should have no problem. If you cannot connect that way, then it is a MySQL issue. If you can connect that way, then its an error in the script. If it is an error in the script, then I would strip it down to the absolute essentials of something like this:
    #!/usr/bin/perl use DBI; use strict; my $dbh; my $db='survey'; my $host='localhost'; my $user='root'; my $pw='whatever'; $dbh = DBI->connect("DBI:mysql:$db", $user, $pw) or die "Database conn +ection not made: $DBI::errstr"; print "Woo Hoo! I connected!\n"; exit;
    If that works, then I would start rebuilding the cgi script from that point.

    All that being said, my guess is that it is a problem with the script since it is unlikely that both MySQL servers you are trying to reach have problems.

    By the way Nik, you really need to develop some basic troubleshooting skills.

    just my 2 cents,
    davidj
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://624330]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found